Enable the CAN Bus
Enabling the CAN bus interface means, that the CAN controller will go in active mode and will be ready for communication. The CAN Bus that we configured in the previous section will be the source of our example. (For more info on how to configure the CAN Bus, click Here). The following code snippets are taken from can_demo.c
found in $:\Micrium\Software\uC-CAN\Examples\<OS> where 'OS' is either NONE (for No-OS), uCOS-II or uCOS-III.
#include "can_bus.h" extern CANBUS_PARA CanCfg; void App_CAN_Startup (void) { CPU_INT16S can_err; ... [1] CanBusInit(0L); [2] /* Initialize CAN Objects & Bus Layer. */ can_err = CanBusEnable((CANBUS_PARA *)&CanCfg); [3] /* Enable CAN Device according to Configuration. */ if (can_err != CAN_ERR_NONE) { while (1); [4] /* Failure Handling Here. */ } /* --------------- uC/OS-III DEMO TASKs --------------- */ ... [4] }
1] Initialization of µC/CAN Messages & Signals are found here. For more information refer to the previous sections for more details.
2] Initialize the CAN Bus Management Layer. This function call must be performed ONLY once, after the reset of the system.
3] Enable the selected/configured CAN Bus. The configuration variable CanCfg
should be the global variable described in the previous section.
4] This is different when running µC/CAN with NO OS. This code snippet is taken from µC/OS-II or µC/OS-III's can_demo.c
file. Please refer to the can_demo.c
file for No OS ('NONE') for more details.
- For µC/OS-II or -III demos, the Operating System will create the required tasks for the demo selected.