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

Gast #4228304
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
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.
Gast #4228586
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.

Antwort schreiben

Eine eigene Frage? Dieser Thread ist über 11 Jahre alt. Stell sie in einem eigenen Thread – dort lesen mehr Leute mit, und sie wird öfter und schneller beantwortet.

Neuen Thread starten

Eine Lösung, Ergänzung oder Rückmeldung zu diesem Thread? Dann antworte hier.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.