...
Sending and receiving CAN frames Frames can be implemented in different many ways. The simplest way is to disable all upper layers and use the CAN frames Frames directly. When using an operating system (e.g. μC/OS-II or -III), the RX and TX communication could be performed within two the same or separate tasks.
Example
The CAN frame reception shall be done within a single RX-Task. Any received CAN frame shall be send back with the fixed CAN Identifier: 0x100.
Source code
Description
...
The following example will demonstrate the reception of a CAN Frame, it will then modify the CAN Identifier (ID) and send the CAN Frame back on the same CAN Bus line. This example is the same as the 'ECHO' example found in the can_demo.c file for your given operating system.
To select the 'ECHO' example make sure that the following is set in can_demo.c:
Code Block | ||||
---|---|---|---|---|
| ||||
/* CAN Demo Definitions. */
#define APP_CAN_RX_TX_DEMO 0u
#define APP_CAN_ECHO_DEMO 1u
/* --------------- uC/CAN DEMO SELECTION -------------- */
/* Select the CAN demo to run. */
#define APP_CAN_DEMO_SELECT APP_CAN_ECHO_DEMO |
Echo Task
Code Block | ||||
---|---|---|---|---|
| ||||
#include "can_frm.h"
#include "can_bus.h"
#if (APP_CAN_DEMO_SELECT == APP_CAN_ECHO_DEMO)
void Echo_Task (void *argp) [1]
{
CANFRM frm;
CPU_INT08U busId;
CPU_INT16U timeout;
(void)&argp; /* Suppress Compiler Warning. */
busId = 0u; [2] /* CAN Device Number/ CAN Controller Number. */
timeout = 0u;
CanBusIoCtl( busId, /* Rx Timeout is set to wait forever for a new Frame. */
CANBUS_SET_RX_TIMEOUT,
&timeout); [3]
while (DEF_ON) { /* Endless while loop. */
CanBusRead( busId, [4] /* Wait for new CAN Frame to Arrive. */
(void *)&frm,
sizeof(CANFRM));
frm.Identifier = 0x100L; [5] /* Change Frame ID. */
CanBusWrite( busId, [6] /* Echo back same data with updated Frame ID. */
(void *)&frm,
sizeof(CANFRM));
}
}
#endif |