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 the previous section info on how to configure the CAN Bus, click Here)
Example
The CAN bus (we have configured in the chapter above) shall be enabled.
Source code
Description
...
. 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.
Code Block | ||||
---|---|---|---|---|
| ||||
#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]
} |
Panel | ||
---|---|---|
| ||
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 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
|