modm API documentation

#include <modm/architecture/interface/can.hpp>

Inheritance diagram for modm::Can:
modm::PeripheralDriver modm::Mcp2515< SPI, CS, INT > modm::platform::Can1 modm::platform::Can2 modm_test::platform::CanDriver

Public Types

enum  Mode : uint8_t { Mode::Normal = 0b00, Mode::ListenOnly = 0b01, Mode::LoopBack = 0b10, Mode::ListenOnlyLoopBack = 0b11 }
 Possible modes of the CAN controller. More...
enum  BusState : uint8_t { BusState::Connected = 0, BusState::ErrorWarning = 1, BusState::ErrorPassive = 2, Off = 3 }

Static Public Member Functions

template<class... Signals>
static void connect ()
template<class SystemClock , bitrate_t bitrate = 125_kbps, percent_t tolerance = 1_pct>
static void initialize (Mode startupMode)
static bool isMessageAvailable ()
 Returns true if a message can be retrieved by calling getMessage.
static bool getMessage (can::Message &message)
 Returns true if a message was copied into the message buffer.
static bool isReadyToSend ()
static bool sendMessage (const can::Message &message)
static uint8_t getReceiveErrorCounter ()
 Get Receive Error Counter.
static uint8_t getTransmitErrorCounter ()
 Get Transmit Error Counter.
static BusState getBusState ()
- Static Public Member Functions inherited from modm::PeripheralDriver
static void initialize ()
 initializes the peripheral, must be called before use.
static void configurePurpose ()
 configures a peripheral for a specific purpose
static void setParameter ()
 sets a parameter
static void getParameter ()
 returns a parameter
static bool getInterruptFlag ()
 Read an interrupt flag.
static void acknowledgeInterruptFlag ()
template<baudrate_t available, baudrate_t requested, percent_t tolerance>
static void assertBaudrateInTolerance ()

Static Public Attributes

static constexpr size_t RxBufferSize = 16
 Size of the receive buffer.
static constexpr size_t TxBufferSize = 16
 Size of the transmit buffer.

Detailed Description

Interface to the CAN bus

Member Enumeration Documentation

enum modm::Can::BusState : uint8_t
Enum ValuesDocumentation

This bit is set by hardware when the warning limit has been reached (Receive Error Counter or Transmit Error Counter ≥ 96).


This bit is set by hardware when the Error Passive limit has been reached (Receive Error Counter or Transmit Error Counter > 127).


This bit is set by hardware when it enters the bus-off state. The bus-off state is entered on TEC overflow, greater than 255

enum modm::Can::Mode : uint8_t

Possible modes of the CAN controller.

Enum ValuesDocumentation

standard operation mode


only possible to receive messages


messages sent are immediately received by own controller


combination of both modes

Member Function Documentation

template<class... Signals>
static void modm::Can::connect ( )

Configures the Tx and Rx signals and connects them.

Template Parameters
SignalsOne Tx and one Rx signal are required and can be passed out-of-order.
template<class SystemClock , bitrate_t bitrate = 125_kbps, percent_t tolerance = 1_pct>
static void modm::Can::initialize ( Mode  startupMode)

Initializes the hardware and sets the baudrate.

Template Parameters
SystemClockthe currently active system clock
bitratethe desired bitrate in Hz
tolerancethe allowed relative tolerance for the resulting baudrate
static bool modm::Can::isReadyToSend ( )

The CAN controller has a free slot to send a new message.

true if a slot is available, false otherwise
static bool modm::Can::sendMessage ( const can::Message message)

Send a message over the CAN.

true if the message was send, false otherwise

The documentation for this class was generated from the following file: