I'm trying to implement a can network over 2 teensy 4.0
i don't know if the issue with connecting to wrong ports i used port 21 and 22
sender code:
receiver code:
i don't know if the issue with connecting to wrong ports i used port 21 and 22
sender code:
#include <FlexCAN_T4.h>
int r;
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can0;
void setup() {
Serial.begin(9600);
can0.begin();
can0.setBaudRate(1000000);
can0.setMaxMB(4);
can0.setMB(MB1, TX, STD);
can0.enableMBInterrupts();
}
void loop() {
can0.events();
CAN_message_t msg;
r=analogRead(A0);
msg.id=0x12;
msg.buf[0]=r;
Serial.println(msg.buf[0]);
if(can0.write(msg))
{
Serial.println("done sending...");
}
else
{
Serial.println("error in sending...");
}
delay(1000);
}
receiver code:
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can0;
void setup() {
Serial.begin(9600);
can0.begin();
can0.setBaudRate(1000000);
can0.setMaxMB(4);
can0.setMB(MB1,RX,STD);
can0.enableMBInterrupts();
}
void loop() {
CAN_message_t msg;
while (can0.read(msg)) {
Serial.print("ID: ");
Serial.print(msg.id, HEX);
Serial.print(" Data: ");
for (int i = 0; i < msg.len; i++) {
Serial.print(msg.buf[i]);
Serial.println(" ");
}
}
can0.events();
}