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?
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]
hey~ sorry for the delay, I see this page just right now!!
yep~ I am the guy Loovee!!
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: [email protected] , I had writen a demo code about how to get OBD data from a vehicle~
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
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?
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());
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.
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?
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.
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…