A CAN driver for the ESP32

Last year I ordered an ESP32, a chip that got quiet a lot of attention because it is small, affordable and comes with a free SDK. I worked with the predecessor, the ESP8266 and I think that the ESP32 is way easier to use and the SDK (called ESP-IDF) is much more powerful compared with the ESP8266.

Time to get hands on the ESP32 as I want a CAN/CANopen-Wifi bridge. The first few months nothing happend and I already thought that the chip will never arrive but finally I got mail from China. I started with a simple "Hello world" but soon found that there is no CAN driver included in the SDK. After some research I found that there is a CAN port and that the CAN module on the ESP32 is SJA1000 compatible.I stripped the driver to work out of the box with the latest SDK version. The code is not perfect (some magic numbers etc.) but should be a good starting point for an own driver.

As I do not want to go to jail because you build something with the code and someone dies:

This software is a PROTOTYPE version and is not designed or intended for use in production, especially not for safety-critical applications! The user represents and warrants that it will NOT use or redistribute the Software for such purposes. This prototype is for research purposes only. This software is provided "AS IS," without a warranty of any kind.


First we need the API definition for CAN:




Register definition


Module Initialization


Interrupt Service Routine (for all interrupts)


Read a Frame from the FIFO


Writing a CAN frame


Stop CAN Module


An example project can be downloaded here:


6 thoughts on “A CAN driver for the ESP32

  1. pallyya

    hi, you had done a very interesting work.
    im interested in developing a can driver for ESP32 and your work is very promising and well coded.
    can i use your code in my academic project and can you send me or post an example.
    thank you in advance.

  2. Pawel Szabaciuk

    "If you need the Code as a example project, post a comment."
    I would like some example if it is not a problem 🙂

  3. Hey guys,

    sorry for the late reply, I just have seen your posts. I will prepare an example project next week, including the latest version of the driver (dynamic baudrate calculation), based on the latest ESP-IDF. Of course you can use the code in your projects but plase not that there is absolutely no warrenty and it comes "AS IS".


    • Pawel Szabaciuk

      Thank you very much!

    • pallyya

      thank you very much, i will try as soon as possible.
      very good work

Leave a Reply


About Thomas Barth

Thomas Barth, born 1986, is a german teaching fellow and Ph.D. student. He studied electrical engineering in Darmstadt, Frankfurt and Helsinki and worked 7 years in industry automation before he switched to embedded systems and microelectronics. To read more about him, click here.