Teensy 4.1 CAN logger

Not open for further replies.


New member
Dear forum members,

I have busted my butt while working on my CAN logger project. My main task is to capture all messages transmitted over CAN and not to lose one. This is crucial. More crucial is the need to save logged CAN frames into an SD card. I have tried few techniques of fulfilling this task, but this is the point where the lack of programming experience hits hard. The main problem is that I loose many CAN frames after a while of logging. I don't know how to implement writing data to SD card by 512 byte blocks. Could this increase speed? And what happens with CAN bus monitoring during data transferring to SD? Should I use multitasking here?
I would appreciate if my humble code would be overviewed by someone more experienced than I am.
Source code attached.

View attachment CAN_logger_internal_SD.ino
you shouldn't loose frames unless you're polling with slow code or some calls are blocking (SD?). You could create 2 512 byte buffers and when one is full, write it but keep logging to the free buffer till thats full, then cycle again. You could also setup a circular queue of 1024 bytes and if it fills to more than 512 bytes dequeue the 512 into a buffer and write it to SD, meanwhile the circular queue is still adding bytes from the log.
Thank you for reply.
This is what I already thought about, but both of cases you mentioned sound like multitasking...? If so, how to implement it? Where could I get more info of multitasking syntax and other tips?

And another thing - is there a certain pattern to follow in order to write the 512 byte block into an SD? Or just File.printf() will do the trick? Because currently my code calls printf() function to every byte. Should I make my own array of characters with the size of [512] and load it into an SD with File.printf(*char[512])?

Quite unclear for now, but I am learning :)
Ok guys thanks for advice, will try it out and report the results. But my concern is what happens with CAN bus monitoring while I write data to an SD card... ?
Not open for further replies.