Configure the CAN Bus

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.

#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                                 */
    }
};

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.

Node & Device Separation

A separation of Bus Node from Device Driver is necessary when different CAN modules are used (i.e. on a processor with integrated CAN module and also external CAN module(s), or with a CAN module with multiple channels).

Example

The MPC565 processor TouCAN has 3 available CAN channles (A, B, C) with the option of also having 3 external SJA1000 CAN modules, having 6 CAN Nodes overall available. However, both the device driver(s) from TouCAN & SJA1000 range from 0-2, and since each CAN node must have it's own unique Bus Node/Driver Device configuration, the following shows a possible configuration of the 6 CAN nodes:

Configuration TouCAN A
Bus node 0
Driver device 0

Configuration TouCAN B
Bus node 1
Driver device 1

Configuration TouCAN C
Bus node 4
Driver device 2

Configuration SJA1000 1
Bus node 5
Driver device 0

Configuration SJA1000 2
Bus node 2
Driver device 1

Configuration SJA1000 3
Bus node 3
Driver device 2

If only one CAN device is used then both the bus node and driver device can be set to equal values.