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 a user file, e.g. the configuration file can_cfg.c, and filled with the corresponding configuration values.

...

CAN Bus Interface Config

The internal CAN bus controller #0 of the TriCore 1796 shall be used for a simple test protocol. The communication parameters are specified to:

  • Standard CAN Identifiers (11 Bits)
  • Baud rate shall be 250 kbit/s

Source code

Description

  1. Configure CAN bus layer to use standard CAN-Identifiers
  2. Bus speed shall be 250000 bit/s
  3. Bus node name for usage in can bus layer
  4. Driver device of low level device drivers
  5. Links to low level device driver functions
  6. Trivial mapping of function codes, which are needed from the low level device driver

Additional Information

...

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                                 */
    }
};
      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
Anchor
ex_canbus_node_device_separation
ex_canbus_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

On a The MPC565 processor TouCAN has 3 available CAN channles (A, B, C are used and also ) with the option of also having 3 external SJA1000 CAN modules. Then , having 6 CAN nodes are available (range 0-5), but driver devices from TouCAN range 0-2 and driver devices from SJA1000 do also range from 0-2.In this case a possible configuration could beNodes 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.