CANFD buffer only reading 8bytes.

KZebu

New member
I am using teensy 4.1 CAN3 port with CJMCU-230 to read CANFD frames ( 64Byte buffer with 32bit Floats). But when I try to print the buffer, it only prints first 8 bytes and rest is 0.

Here is the code:

#include <FlexCAN_T4.h>
FlexCAN_T4FD<CAN3, RX_SIZE_1024, TX_SIZE_16> myFD;
CANFD_message_t msgFD;
void setup(void) {
CANFD_timings_t config;
config.clock = CLK_40MHz;
config.baudrate = 1000000;
config.baudrateFD = 1000000;

myFD.begin();
myFD.setBaudRate(config);
}
void loop() {

if ( myFD.read(msgFD) ) {
Serial.print("CAN1 ");
Serial.print("MB: "); Serial.print(msgFD.mb);
Serial.print(" ID: 0x"); Serial.print(msgFD.id, HEX );
Serial.print(" EXT: "); Serial.print(msgFD.flags.extended);
Serial.print(" LEN: "); Serial.print(msgFD.len);
Serial.print(" DATA: ");
for ( uint8_t i = 0; i < msgFD.len; i++ ) {
Serial.print(msgFD.buf); Serial.print(" ");
}
Serial.print(" TS: "); Serial.println(msgFD.timestamp);
}
}
 
When you post code can you post it between code tags using the </> button.
It makes the code readable for someone who is not familiar with it. See code below.

The code shown above, and below, does NOT compile.

Code:
#include <FlexCAN_T4.h>
FlexCAN_T4FD<CAN3, RX_SIZE_1024, TX_SIZE_16> myFD;
CANFD_message_t msgFD;
void setup(void) {
    CANFD_timings_t config;
    config.clock = CLK_40MHz;
    config.baudrate = 1000000;
    config.baudrateFD = 1000000;

    myFD.begin();
    myFD.setBaudRate(config);
}
void loop() {

    if (myFD.read(msgFD)) {
        Serial.print("CAN1 ");
        Serial.print("MB: "); Serial.print(msgFD.mb);
        Serial.print(" ID: 0x"); Serial.print(msgFD.id, HEX);
        Serial.print(" EXT: "); Serial.print(msgFD.flags.extended);
        Serial.print(" LEN: "); Serial.print(msgFD.len);
        Serial.print(" DATA: ");
        for (uint8_t i = 0; i < msgFD.len; i++) {
            Serial.print(msgFD.buf); Serial.print(" ");
        }
        Serial.print(" TS: "); Serial.println(msgFD.timestamp);
    }
}
 
Back
Top