Flow Control Frame CAN-BUS-Shield

Hi :wink:

I’ve tried to read the VIN of my car with the CAN-BUS-Shield from Seeedstudio.
When I use the following code the response contains only the first three chars of the VIN (TMB).

I found this wikipedia article which describes the flow control frame. http://bit.ly/1JnAYy5

Can someone tell me how I can read the whole VIN with this technique?

    #include <mcp_can.h>
    #include <SPI.h>
    #define CAN_BCAST 0x7df

    MCP_CAN CAN(9);

    unsigned char Flag_Recv = 0;
    unsigned char len = 0;
    unsigned char buf[8];
    char str[20];

    //EXTBYTS MODE PID UNUSED
    unsigned char canBuf[8] = {0x02, 0x09, 0x02, 0, 0, 0, 0, 0};
    unsigned char canFlow[8] = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    void setup() {

      Serial.begin(9600);

    //---------------------------------------------------------------------------------------------------------------
      //Init CAN-Bus
      pinMode(2, INPUT); // Setting pin 2 for /INT input

      Serial.println("Init CAN-BUS...");

      if (CAN.begin(CAN_500KBPS) == CAN_OK)
        Serial.print("Init CAN-BUS done!");
      else
        Serial.print("Init CAN-BUS ERROR!");

      CAN.init_Mask(0, 0, 0x7f0);
      CAN.init_Mask(1, 0, 0x7f0);
      CAN.init_Filt(0, 0, 0x7e0);
      CAN.init_Filt(1, 0, 0x7e0);
      CAN.init_Filt(2, 0, 0x7e0);
      CAN.init_Filt(3, 0, 0x7e0);
      CAN.init_Filt(4, 0, 0x7e0);
      CAN.init_Filt(5, 0, 0x7e0);
    }

    void loop() {
      // put your main code here, to run repeatedly:
      Serial.println();
      Flag_Recv = 0;
      unsigned char vinBuf[8];
     
      CAN.sendMsgBuf(0x7df, 0, 8, canBuf);
      delay(100);
      CAN.readMsgBuf(&len, vinBuf);

      for(int i = 0; i<len; i++)    // print the data
            {
                Serial.print("");
                Serial.print(vinBuf[i], HEX);
                Serial.print("\t");
            }
      Serial.println();


      delay(100);

      CAN.sendMsgBuf(0x7df, 0, 8, canFlow);

      delay(100);

      CAN.readMsgBuf(&len, vinBuf);
       
      for(int i = 0; i<len; i++)    // print the data
            {
                Serial.print("");
                Serial.print(vinBuf[i], HEX);
                Serial.print("\t");
            }
      Serial.println();

      while(1);
    }

Thanks in advance! :slight_smile:

MrDernst

      CAN.readMsgBuf(&len, vinBuf);

What value is written to len? How much data do you expect to be transferred in 100 milliseconds?

PaulS: What value is written to len? How much data do you expect to be transferred in 100 milliseconds?

The first len returns 8 and the second 0. The whole answer I expect is 17-20 bytes.