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.