Teensy 4.1 and CanBus

Hi tonton81. maybe the best approach is if you have or could point me to code examples using the Teensy 4.1 CanFD that include the filtering? just unsure how to use your .h file correctly. thanks boothby
 
Code:
Can0.setMBFilter(REJECT_ALL); // you must first block all frames from being captured (blacklist)

  Can0.enableMBInterrupts(); // enable all reception interrupts
  Can0.onReceive(canSniff); // set your callback
  Can0.setMBFilter(MB0,0x123); // start receiving only 0x123 (whitelist)
  Can0.setMBFilter(MB1,0x456); // also receive 0x456 (whitelist)

it should be same functions in both CAN2.0 and CANFD
 
tonton81.

success. your lines of code as conformation of what i thought reading through the FlexCAN_T4. and why i didn't find your description file on GitHub on that file till today... very helpful.
one of my big issues i added a line of code that printed to serial port 1 which was not initialized. never noticed till this afternoon wondering what that print statement didn't show up on the terminal. Serial1.print that is why i only got 5 calls to the CanSniff() then stopped.
Notice i could not use MB4,5,6 for assigning the mailbox interrupt. not sure why. using your mailboxStatus() showed 7 RX and 7 TX.

question on the hardware. i notice when the sending ID didn't match with the destination, there was still an ack back to the sender. is that correct? would think that the node sending would only received if there was a node matching that ID.

Thanks so much for your help.
Boothby
 
it is similar i guess to UDP, a broadcast that all nodes see. Hardware wise, all nodes will ack the frame itself, but only the specific node will actually reply if it was programmed to do so.

As you check out mailboxStatus you will see some mailboxes as Standard and some as Extended. Keep in mind 0x456 is a standard ID and if lets say MB7 is an Extended mailbox, it will technically receive only extended frames of id 0x456, and a standard frame of same ID is rejected
 
Good afternoon guys. I am using the triplecan board with a teensy 4.0. I am having major issues with 5000000. I can go up to 4000000, and I have changed the speed to 60Mhz, but if I go to my target speed I get nothing. I was wondering if I am missing something basic. I can post my code tonight, I am away from my laptop but wanted to throw the question out as its pretty much the demo from this link…

https://github.com/skpang/Teensy40_triple_CAN_demo/blob/master/Teensy40_triple_CAN_demo.ino

I know this thread is old, but it was all I could find in reference to 5Mb
 
Hi, I am a new student trying to figure out how to make a code that sends out simple can fd messages to a single teensy 4.1 microcontroller. I need help with a sample code that can do this as the example codes I run. come back with many compilation errors and they are not clear and concise. Also, I want to further move my project to matlab.
 
Hi guys,
I have been working on a CAN data logger using a Teensy 4.1 board, my plan is to receive CAN 2.0B messages @ 1 MHz from various sensors and save the useful data into an SD Card.This board is also communicating to a Software Application using CAN and Serial3 links.
The code is running smoothy, I am able to read CAN messages, store the telemetry and do some other stuff.

Right know I am experiencing some problems with my code since it is computing exhaustive that after I send an order from the computer (about 2 CAN frames in length) my Teensy freezes and it is reset. After the reset I am catching the reset cause and the register reads "CPU Lockup".

I think that my bug could be located in the receiving method of the CAN messages, since I am servicing every single CAN message, while I would like to store the messages in a buffer and trigger an interrupt every n received messages. But currently I do not know how to achieve this task.
My current code is the following:

C:
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can;

void setupCan()
{
  can.begin();
  can.setBaudRate(1000000);
  can.setMaxMB(16);
  can.enableDMA();
  can.enableFIFO();
  can.enableFIFOInterrupt();
  can.onReceive(rxCanMessages);
}
void rxCanMessages(const CAN_message_t &msg);   // Service every incoming message

My idea is to receive 32 messages in the FIFO and trigger an interrupt when the buffer is full to read the whole buffer. Another approach is to use two buffers in a ping-pong mode.

Any help would be appreciated.
 
Hi guys,
I have been working on a CAN data logger using a Teensy 4.1 board, my plan is to receive CAN 2.0B messages @ 1 MHz from various sensors and save the useful data into an SD Card.This board is also communicating to a Software Application using CAN and Serial3 links.
The code is running smoothy, I am able to read CAN messages, store the telemetry and do some other stuff.

Right know I am experiencing some problems with my code since it is computing exhaustive that after I send an order from the computer (about 2 CAN frames in length) my Teensy freezes and it is reset. After the reset I am catching the reset cause and the register reads "CPU Lockup".

I think that my bug could be located in the receiving method of the CAN messages, since I am servicing every single CAN message, while I would like to store the messages in a buffer and trigger an interrupt every n received messages. But currently I do not know how to achieve this task.
My current code is the following:

C:
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can;

void setupCan()
{
  can.begin();
  can.setBaudRate(1000000);
  can.setMaxMB(16);
  can.enableDMA();
  can.enableFIFO();
  can.enableFIFOInterrupt();
  can.onReceive(rxCanMessages);
}
void rxCanMessages(const CAN_message_t &msg);   // Service every incoming message

My idea is to receive 32 messages in the FIFO and trigger an interrupt when the buffer is full to read the whole buffer. Another approach is to use two buffers in a ping-pong mode.

Any help would be appreciated.

It would be much easier to provide help if you would post a complete sketch. This would allow others to load & compile your sketch locally, as well as to evaluate your complete sketch for errors, etc. With the minimal snippet that you posted, it is almost impossible to provide any kind of meaningful advice.

Mark J Culross
KD5RXT
 
Back
Top