Hello,
I have the volvo s80 car 2008, i trying to capture steering wheel button
presses, the problem is when i press the two different buttons i receive
the same can-bus message, for example:
1. When i press "Exit" button i receive:
canId = 0x7A, message = 0x0 9F 80 0 0 0 0 21 0
2. When i press "Enter" button i receive the same message:
canId = 0x7A, message = 0x0 9F 80 0 0 0 0 21 0
If i press other buttons(for example "cruise control start" on steering
wheel or some button on radio) i receive uniqueness messages and last
bytes changes for each other button presses.
I'm using arduino and can-bus shield(elecfreaks), maybe somebody can
help me and explain what can be wrong, here is my arduino sketch:
#include <SPI.h>
#include "mcp_can.h"
const int SPI_CS_PIN = 10;
MCP_CAN CAN(SPI_CS_PIN); // Set CS
pin
void setup()
{
Serial.begin(115200);
START_INIT:
if(CAN_OK == CAN.begin(CAN_125KBPS))
{
Serial.println("CAN BUS Shield init ok!");
}
else
{
Serial.println("CAN BUS Shield init fail");
Serial.println("Init CAN BUS Shield again");
delay(100);
goto START_INIT;
}
}
void loop()
{
unsigned char len = 0;
unsigned char buf[8];
if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data
coming
{
CAN.readMsgBuf(&len, buf); // read data, len: data length,
buf: data buf
unsigned char canId = CAN.getCanId();
Serial.println("-----------------------------");
Serial.println("get data from ID: ");
Serial.println(canId);
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i]);
Serial.print("\t");
}
Serial.println();
}
}
just a thought but maybe the buffer is too small, or more than 1 message is coming and the buffer gets overwritten.
I cannot see, that you release the one read message. I'm the meaning you read everytime the same one. In other case, if readMsgBuf() release automatically the message, you would read the CAN Id from a new message, that at the moment is not available. I don't know the arduino API. Please check which case is the right one depend you documentation of the API.
Looks like reading happens fine, first arduino read canID and after he read the message and this happenes in a loop. About the buffer i will try to increase the buffer size.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.