I switched one of the CAN Bus Transceivers with no luck. Here are the code and the photos of what I have so far.
Receiver:
Code:
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_64> Can0;
void setup(void) {
Serial.begin(115200); delay(400);
pinMode(6, OUTPUT); digitalWrite(6, LOW); /* optional tranceiver enable pin */
Can0.begin();
Can0.setBaudRate(500000);
Can0.setMaxMB(16);
Can0.enableFIFO();
Can0.enableFIFOInterrupt();
Can0.onReceive(canSniff);
Can0.mailboxStatus();
Can0.enableMBInterrupts();
pinMode(13, OUTPUT);
}
void canSniff(const CAN_message_t &msg) {
Serial.print("MB "); Serial.print(msg.mb);
Serial.print(" OVERRUN: "); Serial.print(msg.flags.overrun);
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" EXT: "); Serial.print(msg.flags.extended);
Serial.print(" RTR: "); Serial.print(msg.flags.remote);
Serial.print(" TS: "); Serial.print(msg.timestamp);
Serial.print(" ID: "); Serial.print(msg.id, HEX);
Serial.print(" Buffer: ");
for ( uint8_t i = 0; i < msg.len; i++ ) {
Serial.print(msg.buf[i], HEX); Serial.print(" ");
} Serial.println();
static uint32_t _time = millis();
Serial.print("Time between frames: ");
Serial.println(millis() - _time);
_time = millis();
}
Sender:
void loop() {
}
Code:
#include <FlexCAN_T4.h>
#include <elapsedMillis.h>
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_128> LCAN;
elapsedMillis tsk1000msCounter;
CAN_message_t msg0E0;
void setup() {
LCAN.begin();
LCAN.setClock(CLK_60MHz);
LCAN.setBaudRate(500000);
LCAN.setMaxMB(10);
LCAN.setMB(MB0, RX); /* Set Mailbox RX Direction */
LCAN.setMB(MB1, RX); /* Set Mailbox RX Direction */
LCAN.setMB(MB2, RX); /* Set Mailbox RX Direction */
for (int i = 4; i < 10; i++) LCAN.setMB((FLEXCAN_MAILBOX)(i), TX); /* Set Mailbox TX Direction */
msg0E0.id = 0x0E0;
msg0E0.len = 5; // Data length
Serial.begin(500000); delay(1000);
LCAN.onReceive(canSniff);
LCAN.enableMBInterrupts();
Serial.print("LCAN Setup: ");
LCAN.mailboxStatus();
}
void loop() {
if (tsk1000msCounter >= 1000) {
tsk1000msCounter = 0; // Reset 1000ms timer
msg0E0.buf[0]++;
LCAN.write(msg0E0);
}
}
void canSniff(const CAN_message_t &msg) {
Serial.print("MB "); Serial.print(msg.mb);
Serial.print(" OVERRUN: "); Serial.print(msg.flags.overrun);
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" EXT: "); Serial.print(msg.flags.extended);
Serial.print(" RTR: "); Serial.print(msg.flags.remote);
Serial.print(" TS: "); Serial.print(msg.timestamp);
Serial.print(" ID: "); Serial.print(msg.id, HEX);
Serial.print(" Buffer: ");
for ( uint8_t i = 0; i < msg.len; i++ ) {
Serial.print(msg.buf[i], HEX); Serial.print(" ");
} Serial.println();
static uint32_t _time = millis();
Serial.print("Time between frames: ");
Serial.println(millis() - _time);
_time = millis();
}


