Good morning guys
I have been trying all morning to make a simple CAN communication but there is no way (I have read several threads about it in this forum)
I write this code:
But no send / receive anything. Use a TJA1051T transceiver. Also use a USB/CAN adaptor to check connection, but no receive any message and if send a message Teensy no receive it.
Any idea?
I have been trying all morning to make a simple CAN communication but there is no way (I have read several threads about it in this forum)
I write this code:
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can2;
CAN_message_t msg;
void setup() {
Serial.begin(115200);
can2.begin();
can2.setBaudRate(250000);
}
void loop() {
msg.id = 0x100;
msg.len = 8;
msg.flags.extended = 0;
msg.flags.remote = 0;
msg.flags.overrun = 0;
msg.flags.reserved = 0;
msg.buf[0] = 10;
msg.buf[1] = 20;
msg.buf[2] = 0;
msg.buf[3] = 100;
msg.buf[4] = 128;
msg.buf[5] = 64;
msg.buf[6] = 32;
msg.buf[7] = 16;
can2.write(msg);
if ( can2.read(msg) ) {
Serial.print("CAN2 ");
Serial.print("MB: "); Serial.print(msg.mb);
Serial.print(" ID: 0x"); Serial.print(msg.id, HEX );
Serial.print(" EXT: "); Serial.print(msg.flags.extended );
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" DATA: ");
for ( uint8_t i = 0; i < 8; i++ ) {
Serial.print(msg.buf); Serial.print(" ");
}
}
}
But no send / receive anything. Use a TJA1051T transceiver. Also use a USB/CAN adaptor to check connection, but no receive any message and if send a message Teensy no receive it.
Any idea?