CAN - Shield Serial Monitor

Hi,

I’m a newbie and purchased the arduino uno and can bus shield recently. I’ve downloaded the example from the wiki and at first it didn’t work. after searching the forum
i realized that the “serial.begin ()” so i added it to the code.
I also downloaded the example again from the forum and the wiki to make sure every thing is ok…

So now when i start the controller and plug it to the vehicle CAN, all i get is a “y” with 2 dots above it.
I checked the code and it looks ok, but it doesn’t do anything besides the y with 2 dots.

It compile OK so I’m kinda in the dark here…

after looking carefully it looks to me like it will never go into the if statement. And even if it will enter, it will do it only once…
am I correct?

[code]// demo: CAN-BUS Shield, receive data
#include “mcp_can.h”
#include <SPI.h>
#include <stdio.h>
#define INT8U unsigned char

INT8U Flag_Recv = 0;
INT8U len = 0;
INT8U buf[8];
char str[20];
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();
}
}[/code]

P.S.

Great committing in the headers files loovee…

hey~ sorry for the delay, I see this page just right now!!
yep~ I am the guy Loovee!! :smiley:
seems like that you plug your can-bus to a vehicle, and it doesn’t works right ?
well~ maybe you can contract with me by email: luweicong@seeedstudio.com , I had writen a demo code about how to get OBD data from a vehicle~ :wink:

one more thing, cu’z the amount of data from a vehicle is very large which may cause can-bus crash, you can try to set the mask to avoid some unwanted data :slight_smile:

Hi loovee,

I got busy so I went back to it right now…

Anyways, I tried your code on a stand alone ECU and at first it worked great. But then the next day i couldn’t get it to work. so i took it out of the car and it worked again.
Then i put it back and still doesn’t work.
From what i have seen it doesn’t go into the interrupt. So it wont work…
Also I can’t seem to use the functions of the API. I tried to test it with the checkError function but the compiler says it wasn’t declared in this scope.

My questions is why would it not recognize the function?
How do i read the MCP_EFLG register to know what’s wrong?

I’ll email you for the code…

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()); 

}[/code]

try this :

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

I have same problem that interrupt doesn’t work.
Could you show me your OBD sample code?

please refer to github.com/reeedstudio/CANBUS_S … BD_RECIPLE
:sunglasses:

hi , can someone explain to me how to do filter and masking ?

thanks,

Hi Loovee,

I have a few question regarding the code:

  1. Why when add a Serial.print to the “loop” loop that’s all that happen? I mean outside the Flag_rcv condition it seems to not work.

  2. I did as suggested after testing with Serial.print, and every now and then i get the error code ‘5’. How can i know what exactly is the problem?
    what bit was on the register to identify the problem?

  3. Sometimes it hangs at the setup loop. It usually happens after i’ll start the engine. Do you have sepculation why is it acting like this?

And I would like also an explanation about the filters and masks.

Thanks!!

Hi Loovee,

Did you have a chance to look at the question?
Specifically, How do i look at the registers to know what is the error if have one?

Thanks a lot.

hey, sorry that I did notice this question earlier ~

:frowning:

That’s ok. So, is it possible? Can i look atthe registers to know what’s the problem exactly?
Right now the solution i came up with is the initialize the mcp2515…
But it’s kind of stuipd solution in my opinion…