CAN Bus Protocol Implementation

Gaurav K picture Gaurav K · Mar 3, 2013 · Viewed 11.2k times · Source

I want to learn and implement CAN BUS protocol. I have implemented UART,SPI,I2C and One Wire Bus protocol using MSP430 Launchpad in software. Now I want to learn about CAN Bus protocol. I have mBed LPC 1768 Cortex M3 Development board. mBed has Can Bus Library but I want to write my own library so that I can learn it in detail, i.e. the way I did for other communication protocols.

I am not able to find suitable resources to start with and the material appears to be scattered on net. Can any one guide how do i write and implement CAN Bus protocol with the development boards available with me.

Thanks

Answer

Swanand picture Swanand · Mar 14, 2013

Developing CAN library is relatively easy as compared to I2C or SPI. This is because CAN Controller of your Cortex will take care of most of complex things.

To transmit the data, You have to write ID and Data in designated registers and set bit to transmit data.

This Application note from NXP can be very useful for you.

I would recommend you to implement following functions:

  1. InitCAN - This should set specified Baud Rate of CAN.
  2. SetFilters - Most CAN Controllers come with Acceptance Filters, So it's good to have that
  3. SendData - Make sure you accept Parameters like ID_Type and RTRs etc.
  4. RecieveData - This can be blocking or Interrupt based.

Before beginning, do read CAN Basics to understand. Application notes AN713 and AN754 from Microchip is a good source. Also Vector's site and Wikipedia Article.

Plus, You can always post your doubts here or on Electronics.StackExchange.com :)