Nations Technologies Inc.
Tel
:
+86-755-86309900
:
Address: Nations Tower, #109 Baoshen Road, Hi-tech Park North.
Nanshan District, Shenzhen, 518057, P.R.China
570
/
631
CAN Configuration Flow
This chapter will introduce common configuration procedure of CAN while other details like functions of each mode
and register bits are revealed in other part of this manual. CAN configuration flow can divided into serval phases.
Some of the configurations can be changed anytime as long as prior requirements are satisfyied (e.g., filter value).
Preparation Stage:
1.
Configure RCC to enable CAN clock
2.
Configure RCC to enable AFIO and GPIO clock
3.
Write into GPIO registers to map CAN TX and CAN RX signals to desired GPIO pins.
Basic Configuration Stage:
1.
After reset CAN device starts with Sleep mode.
2.
Exit Sleep mode by clearing CAN_MCTRL.SLPRQ bit.
3.
Enter Initialization mode by setting CAN_MCTRL.INIRQ bit.
4.
Wait for CAN_MSTS.INIAK bit become 1 (enter Initilization mode).
5.
Configure bit timing for CAN by writing value to CAN_BTIM.BSJW, CAN_BTIM.TBS2, CAN_BTIM.TBS1
and CAN_BTIM.BRTP bits. Baud rate of CAN bus is defined by the formula below:
𝐵𝑎𝑢𝑑𝑅𝑎𝑡𝑒 =
1
(1 + (𝑇𝐵𝑆1 + 1) + (𝑇𝐵𝑆2 + 1)) ∗ (𝐵𝑅𝑇𝑃 ∗ 𝑡
𝑝𝑐𝑙𝑘
)
6.
Configure work mode options for CAN by writing to CAN_BTIM.SLM (silent) or CAN_BTIM.LBM in register.
7.
Configure CAN behavior(TTCM,ABOM,AWKUM,NART,RFLM,TXFP) through CAN_MCTRL. Most of the
configuration in this register can be changed on the fly but its advised not to do so. Otherwise during few cycles,
CAN behavior will become unpredictable.
8.
Exit Initialization mode by clearing CAN_MCTRL.INIRQ bit.
9.
Wait for CAN_MSTS.INIAK bit become 0 (exit Initilization mode).
10.
User can use filters to filter the messages they want to receive. To configure filter, user needs to write ‘1’ to
CAN_FMC.FINITM bit to request the filters to enter initialization mode. When filter is in initialization mode,
CAN stops reception.
11.
Configure each filter for working mode (CAN_FM1), filter scale (CAN_FS1) and filter assignment
(CAN_FFA1). User can also change filter value (CAN_FiRx) during this time. After completing filter
configuration, clear CAN_FMC.FINITM bit to exit initialization for filters.
For transmission:
1.
Enable the necessary transmit related interrupt CAN_INTE.TMEITE bit.
2.
Check status bits of each mailbox in CAN_TSTS. If any mailbox with TMEMx (x = 0~2) is ‘1’, user can write
the message, which is waiting for transmission, to the corresponding mailbox address. CAN_TMIx.TXRQ(x =