CAN-BUS shield + arduino, different buttons but same message

Gast #4228304
Lesenswert?

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();
    }
}
#4228354
Lesenswert?

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.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren