Hi,
I want to communicate with automotive sensors via CAN-Bus on the teensy 4.1. I'm using the SN65HVD230D with the FlexCAN_T4 library. Receiving works, sending messages doesn't. As soon as I use the FlexCAN_T4 .write() function receiving no longer works, either. The .write() function has no physical influence on the CAN bus. I measured it per Oscilloscope.
This code is not working. However if I comment out the sendCANtestMessage() function, receiving is working:
Any ideas why the .write() function is not working here?
I want to communicate with automotive sensors via CAN-Bus on the teensy 4.1. I'm using the SN65HVD230D with the FlexCAN_T4 library. Receiving works, sending messages doesn't. As soon as I use the FlexCAN_T4 .write() function receiving no longer works, either. The .write() function has no physical influence on the CAN bus. I measured it per Oscilloscope.
This code is not working. However if I comment out the sendCANtestMessage() function, receiving is working:
Code:
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can1;
elapsedMillis timer = 0;
void setup() {
Serial.begin(115200);
Serial.println("setup start");
can1.begin();
can1.setBaudRate(500000);
}
void loop() {
if (timer > 100) {
timer = 0;
sendCANtestMessage();
Serial.println("Send Test CAN Message");
CAN_message_t inMsg;
if (can1.read(inMsg)) {
Serial.print("CAN1 ");
Serial.print("MB: ");
Serial.print(inMsg.mb);
Serial.print(" ID: 0x");
Serial.print(inMsg.id, HEX);
Serial.print(" EXT: ");
Serial.print(inMsg.flags.extended);
Serial.print(" LEN: ");
Serial.print(inMsg.len);
Serial.print(" DATA: ");
for (uint8_t i = 0; i < 8; i++) {
Serial.print(inMsg.buf[i]);
Serial.print(" ");
}
Serial.print(" TS: ");
Serial.println(inMsg.timestamp);
}
}
}
void sendCANtestMessage() {
CAN_message_t outMsg;
outMsg.id = 0xFF;
outMsg.len = 8;
outMsg.flags.extended = 0;
for (byte i = 0; i < 8; i++) {
outMsg.buf[i] = i;
}
can1.write(outMsg);
}
Any ideas why the .write() function is not working here?
