Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Test

Application Signals and Messages

Below, we will show the use of CAN Signals and Messages using the 'Rx / Tx' example in can_demo.c.This demo will use multiple tasks to read, write, and update CAN Signals and Messages. This demo assumes that CAN Signals, Messages, and Bus configuration and initialization have already been done. This example completes the information provided in the previous sections.

To select the 'Rx / Tx' example make sure that the following is set in can_demo.c:

                                                                 /* 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_RX_TX_DEMO

RxTask

 

The communication protocol uses in most cases only the CAN messages. The application is responsible for the values of the mapped CAN signals. The following source code completes the example, started in chapter 6.4 Defining CAN Signals and Messages:

Source code (Protocol RX-Task)

This task could be started within Com_Start() to enable the receive activities as soon as the CAN bus is active.

Description

  1. Local variable to hold the received CAN frame.
  2. Local variable to hold the handle to message of received CAN identifier
  3. Set the RX timeout to 0 to enable the blocking mode, e.g. the function CanBusRead() will wait forever for a CAN frame.
  4. Wait for the next received CAN frame on CAN node 0.
  5. After reception, open the message with the received identifier.
  6. On success, write the received CAN frame to this message. This results in decomposing the CAN frame to all linked CAN signals.

Source code (Protocol Transmit Status)

This function can be called in your transmission task to transmit a specific CAN message, or called within a callback function to transmit information in response to a received CAN message.

Description

  1. Local variable to hold the CAN frame for transmission.
  2. Local variable to hold the handle to message which shall be transmitted
  3. Open the CAN message with the CAN-Identifier 0x150.
  4. On success, read the message to the local CAN frame. This results in collecting all linked signals and writing all information to the CAN frame at the defined locations.
  5. Send this constructed CAN frame via the CAN bus 0.
  • No labels