Sending and receiving CAN frames can be implemented in different ways. The simplest way is to disable all upper layers and use the CAN frames directly. When using an operating system (e.g. μC/OS), the RX and TX communication could be performed within two 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
- Local variable to hold the received and echoed CAN frame.
- Set the RX timeout to 0 to enable the blocking mode, e.g. the function
CanBusRead()
will wait for a CAN frame forever. Otherwise set a timeout and check returned error code of -3- if a timeout has occurred. - Wait for the next received CAN frame.
- After reception, change the CAN-Identifier in received frame
- Send the received CAN frame with changed CAN-Identifier