I have been playing with the FlexCAN T4 library with my Teensy 4 and I have been trying to send a series of different ID data frames out of the T4. This data I aim to use as a data simulation for another project. I can see data on the can bus, using a logic analyser, but it is always the same ID, the lowest number, in my case 'msg.id = 210'. The next ID, 'msg1.id = 300' doesn't appear unless 300 is the lowest number.
I have a short program listing that is probably completely incorrect but I thought I could send one message then send another different message after a short delay and it would appear on the Can Bus.
I have had a quick stab at using Mailboxes but I get the same result, I even added a 'toggling' integer so that it would only send one message at each pass through.
Could anybody point me in the right direction, please.
I have a short program listing that is probably completely incorrect but I thought I could send one message then send another different message after a short delay and it would appear on the Can Bus.
Code:
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> CCT;
static CAN_message_t msg, msg1;
void setup(void)
{
CCT.begin();
CCT.setBaudRate(500000); // I like to set the baud rates just to be on the safe side
}
void loop(void)
{
msg.id = 300;
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] = 255;
msg.buf[3] = 100;
msg.buf[4] = 128;
msg.buf[5] = 64;
msg.buf[6] = 32;
msg.buf[7] = 16;
CCT.write(msg);
delay(1000);
msg1.id = 210;
msg1.len = 8;
msg1.flags.extended = 0;
msg1.flags.remote = 0;
msg1.flags.overrun = 0;
msg1.flags.reserved = 0;
msg1.buf[0] = 240;
msg1.buf[1] = 2;
msg1.buf[2] = 25;
msg1.buf[3] = 10;
msg1.buf[4] = 18;
msg1.buf[5] = 54;
msg1.buf[6] = 22;
msg1.buf[7] = 36;
CCT.write(msg1);
delay(1000);
}
I have had a quick stab at using Mailboxes but I get the same result, I even added a 'toggling' integer so that it would only send one message at each pass through.
Code:
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> CCT;
CAN_message_t msg, msg1;
int r = 0;
// -------------------------------------------------------------
void setup(void)
{
Serial.begin(115200);
CCT.begin();
CCT.setBaudRate(500000); // I like to set the baud rates just to be on the safe side
CCT.reset();
CCT.setMBFilter(REJECT_ALL);
CCT.setMB(MB1,TX);
CCT.setMB(MB2,TX);
CCT.events();
}
void loop(void)
{
if (r==0) {
msg.id = 300;
msg.len = 8;
msg.seq = 1;
msg.buf[0] = 10;
msg.buf[1] = 20;
msg.buf[2] = 255;
msg.buf[4] = 128;
msg.buf[5] = 64;
msg.buf[6] = 32;
msg.buf[7] = 16;
CCT.write(msg);
r=1;
}
else
{
msg1.id = 210;
msg1.len = 8;
msg1.seq = 1;
msg1.buf[0] = 240;
msg1.buf[1] = 2;
msg1.buf[2] = 25;
msg1.buf[3] = 10;
msg1.buf[4] = 18;
msg1.buf[5] = 54;
msg1.buf[6] = 22;
msg1.buf[7] = 36;
CCT.write(msg1);
r=0;
}
delay(1000);
}
Could anybody point me in the right direction, please.