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 6 Next »

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. can_cfg.c, and filled with the corresponding configuration values.

Example: 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:

    #include can_bus.h

    /* CAN Bus Configuration */

    const CANBUS_PARA CanCfg = {

    CAN_FALSE, /*-1-*/

    250000L, /*-2-*/

    0L, /*-3-*/

    0L, /*-4-*/

    TC1796_Init, TC1796_Open, TC1796_Close, /*-5-*/

    TC1796_IoCtl, TC1796_Read, TC1796_Write,

    { 10, 11, 12, 13, 14, 15, 16} /*-6-*/

    };

    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

    1. The CAN bus configuration in the example is done as a global constant to safe RAM space and get a write protected configuration.

    2. This variable must be declared global, because the configuration data will be read during initialization and using the CAN bus layer.

    3. Separation of bus node from driver device is necessary when different CAN modules are used, i.e. on a processor with integrated CAN module and also external CAN module(s).

    Example: On a MPC565 processor TouCAN A, B, C are used and also 3 external SJA1000 CAN modules. Then 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 be:

    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 bus node and driver device can be set to equal values.

    • No labels