LAB: CAN bus

  • Get practical experience with CAN bus communication
  • Create hardware circuitry necessary for the CAN bus

You need to work with your lab partner for this lab. Be sure to pair program and not work independently on this lab.


Part 0: Interface two boards over CAN transceiver

CAN bus requires additional hardware that will be interfaced to your board.


Part 1: Configure the CAN driver

Reference the following starter code for details.

#include "can_bus.h"

void periodic_callbacks__initialize(void) {
  // TODO: initialize your CAN bus
  // Read can_bus.h for more details


Part 2: Send and receive messages

Setup your code in a 10 or 100Hz task:

  • Transmit a test message
  • Receive all messages enqueued by your CAN driver

Reference the following starter code for details.

#include "can_bus.h"

void periodic_callbacks__100Hz(uint32_t callback_count) {
  // TODO: Send a message periodically

  // Empty all messages received in a 100Hz slot
  while (can__rx(...)) {



Part 3: Simple CAN bus application
  • Build a meaningful communications' application
    • For example, if Board=A senses a switch pressed, then send a 1-byte message with 0xAA, otherwise send 0x00 if button is not pressed
  • On Board-B, simply light up an LED (or otherwise turn it off) based on the CAN message data
  • For robustness, if the CAN Bus turns off, simply turn it back on at 1Hz (every 1000ms)



This assignment gives you an overview of practical use of the CAN Bus, and later, by utilizing the DBC file and auto-generation of code, sending and receiving data becomes very easy.

While this provides bare bones knowledge of how communication works, the future lectures will focus on the application layer while abstracting away the details of CAN messages' data encoding and decoding.

Be sure to submit a Merge Request of your Git repository to get credit for the assignment

Back to top