I found myself needing to write some test code to implement CAN (and CAN-FD) on an Atmel SAMC21 microcontroller.
What documentation and example code Atmel provides for implementing CAN on the SAMC21 is lacking. So much of Atmel's documentation consists of long-winded drivel about function X having parameters Y and Z... information that is already apparent from the function prototypes. Such information could have been just as easily algorithmically generated by software (without paying someone to write up these pointless documents), and it still would have been just as equally useless (but less expensive).
However, in an interesting twist of fate, Atmel already has helpful (and open-source) example CAN code as part of a software library for the SAMA5D2 processor.
Both processors share the same Bosch M_CAN peripheral, so the code was thankfully portable.
So, with a little modification, that same code will run on a SAMC21. I have placed the result here in case it helps someone else.
Side note: the modification primarily consists of simply adapting the names of peripheral registers. Some masochist at Atmel decided to provide SAMC and SAMD family register definition include files that implement every single register as a union of a uint32_t called "reg" along with a struct providing a bit field. This means that every single register access has to use the added suffix ".reg"; it makes me want to scream in agony. When something adds extra pointless work for the developer, it is not an improvement.
back to main page contact