Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To configure a CAN bus interface, a global (optional: const) variable of the type CANBUS_PARA (defined in can_bus.h) must be allocated in the configuration file can_cfg.c, and filled with the corresponding configuration values.

CAN Bus Interface Config

The RX600 CAN Driver will be used as an example to describe the communication parameters required in can_cfg.c.

Code Block
languagecpp
linenumberstrue
#include  "can_bus.h"

const  CANBUS_PARA  CanCfg = {                                  /* --------------- CAN BUS CONFIGURATION -------------- */
    CAN_FALSE,                                   [1]            /* EXTENDED FLAG                                        */
    1000000L,                                    [2]            /* BAUDRATE                                             */
    0,                                           [3]            /* BUS NODE                                             */
    0,                                           [4]            /* BUS DEVICE                                           */
                                                 [5]            /* DRIVER FUNCTIONS                                     */
    RX600_CAN_Init,                                             /*      Init                                            */
    RX600_CAN_Open,                                             /*      Open                                            */
    RX600_CAN_Close,                                            /*      Close                                           */
    RX600_CAN_IoCtl,                                            /*      IoCtl                                           */
    RX600_CAN_Read,                                             /*      Read                                            */
    RX600_CAN_Write,                                            /*      Write                                           */
    {                                                           /* DRIVER IO FUNCTION CODES                             */
        IO_RX600_CAN_SET_BAUDRATE,               [6]            /*      Set Baud Rate                                   */
        IO_RX600_CAN_START,                                     /*      Start                                           */
        IO_RX600_CAN_STOP,                                      /*      Stop                                            */
        IO_RX600_CAN_RX_STANDARD,                               /*      Rx Standard                                     */
        IO_RX600_CAN_RX_EXTENDED,                               /*      Rx Extended                                     */
        IO_RX600_CAN_TX_READY,                                  /*      Tx Ready                                        */
        IO_RX600_CAN_GET_NODE_STATUS,                           /*      Get Node Status                                 */
    }
};


Panel
bgColor#f0f0f0

1] Configure CAN Bus Layer to use Standard CAN-Identifiers (Standard 11 Bit IDs)

  • To use the Extended IDs this parameter must be changed to CAN_TRUE.

2] Bus speed is set to 1000000 bit/s or 1Mbits/s.

3] Bus Node Name for Usage in Can Bus Layer. See Node & Device Separation section for more details.

4] Driver device of lower level device drivers. See Node & Device Separation section for more details.

5] Links to low-level device driver functions, such as Open(), Close(), Read(), Write() etc.

6] Required mapping of function codes needed for the low-level device driver CAN_IoCtl() function.


A CAN Bus Configuration MUST be declared global because the configuration data will be used both during initialization and in the CAN Bus Layer. Also, it is done this way to save RAM Space and get a write-protected configuration.

...