Quantcast
Channel: Seeedstudio Forum
Viewing all articles
Browse latest Browse all 6612

CAN - Shield Serial Monitor

$
0
0
giliepin wrote:There's something that i dont understand. Why when I add the function of printing the error on the monitor I dont get any interrupts?
This is very strange to me
Code:void setup()
{
  CAN.begin(CAN_500KBPS);                   // init can bus : baudrate = 500k
  attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt
  Serial.begin(115200);
}

void MCP2515_ISR()
{
     Flag_Recv = 1;
}

void loop()
{
   
    if(Flag_Recv)                   // check if get data
    {
      Flag_Recv = 0;                // clear flag
      CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf
      Serial.println("CAN_BUS GET DATA!");
      Serial.print("data len = ");Serial.println(len);
      for(int i = 0; i<len; i++)    // print the data
      {
        Serial.print(buf[i]);Serial.print("\t");
      }
      Serial.println();
      Serial.print ("RPM:  ");Serial.print(RPMreading(buf[0],buf[1]));Serial.print("\t");//print the decimal value of the RPM
      Serial.print ("GEAR: ");Serial.print(buf[3]);Serial.print("\t");                   //print the decimal value of the GEAR
      Serial.print ("BATT: ");Serial.print(BATTreading(buf[4],buf[5]));Serial.print("\t");//print the decimal value of the BATTERY
      Serial.print ("ET: ");Serial.print(ETreading(buf[6],buf[7]));Serial.print("\t");//print the decimal value of the ENGINE TEMP
      Serial.println();
     
     }

       
      Serial.print ("value of error register: ");
      Serial.println (CAN.checkError());
     
}


try this :

Code:unsigned char err = CAN.checkError();
if(err!= CAN_OK)
{
Serial.print ("value of error register: ");
Serial.println (err);
}


Statistics : Posted by giliepin • on Tue Feb 26, 2013 8:10 pm • Replies 10 • Views 601

Viewing all articles
Browse latest Browse all 6612

Trending Articles