SLAAEN4 March   2025 MSPM0G1106 , MSPM0G1107 , MSPM0G1506 , MSPM0G1507 , MSPM0G1518 , MSPM0G1519 , MSPM0G3106 , MSPM0G3106-Q1 , MSPM0G3107 , MSPM0G3107-Q1 , MSPM0G3506 , MSPM0G3506-Q1 , MSPM0G3507 , MSPM0G3507-Q1 , MSPM0G3518 , MSPM0G3518-Q1 , MSPM0G3519 , MSPM0G3519-Q1

 

  1.   1
  2.   Abstract
  3.   Trademarks
  4. 1Introduction
    1. 1.1 Bridge Between CAN and UART
  5. 2Implementation
    1. 2.1 Principle
    2. 2.2 Structure
  6. 3Software Description
    1. 3.1 Software Functionality
    2. 3.2 Configurable Parameters
    3. 3.3 Structure of Custom Element
    4. 3.4 Structure of FIFO
    5. 3.5 UART Receive and Transmit (Transparent Transmission)
    6. 3.6 UART Receive and Transmit (Protocol Transmission)
    7. 3.7 CAN Receive and Transmit
    8. 3.8 Application Integration
  7. 4Hardware
  8. 5Application Aspects
    1. 5.1 Flexible structure
    2. 5.2 Optional Configuration for CAN
    3. 5.3 CAN Bus Multi-Node Communication Example
  9. 6Summary
  10. 7References

Configurable Parameters

All the configurable parameters are defined in user_define.h, which are listed in Configurable Parameters.

For UART, both transparent transmission and protocol transmission are supported in this example. These functions can switch by defining UART_TRANSPARENT or UART_PROTOCOL.

In transparent transmission, users can configure timeout for detecting one UART message receiving done.

In protocol transmission, users can configure the ID length for different formats. Please note there is a fixed 2-byte header (0×55 0×AA) and 1 byte data length. To modify the format more, users can require modifying the code directly.

#define UART_TRANSPARENT
#ifdef UART_TRANSPARENT
/* The format of Uart:
     * Transparent transmission - Data1 Data2 ...*/
#define UART_TIMEOUT  (0x4000)      //timeout 250ms
#else
#define UART_PROTOCOL
/* The format of Uart:
     * if UART_ID_LENGTH = 4, format is 55 AA ID1 ID2 ID3 ID4 Length Data1 Data2 ...
     * if UART_ID_LENGTH = 1, format is 55 AA ID Length Data1 Data2 ...
     * if UART_ID_LENGTH = 0, format is 55 AA Length Data1 Data2 ...*/
//#define UART_ID_LENGTH  (0)
//#define UART_ID_LENGTH  (1)
#define UART_ID_LENGTH  (4)
#endif

For CAN, ID and data length are included in CAN frame. Users can add another ID in the data area by changing the CAN_ID_LENGTH. (Default value is 0).

/* The format of CAN:
     * if CAN_ID_LENGTH = 4, format is ID1 ID2 ID3 ID4 Data1 Data2 ...
     * if CAN_ID_LENGTH = 1, format is ID Data1 Data2 ...
     * if CAN_ID_LENGTH = 0, format is Data1 Data2 ...*/
#define CAN_ID_LENGTH  (0)
//#define CAN_ID_LENGTH  (1)
//#define CAN_ID_LENGTH  (4)

Table 3-2 Configurable Parameters
Parameter Optional Value Description
#define UART_TRANSPARENT Define / Not defined Enable the UART transparent transmission.
#define UART_PROTOCOL Define / Not defined Enable the UART protocol transmission.
#define UART_TIMEOUT (0x4000) Timeout = UART_TIMEOUT / 32768 s Timeout to indicate one UART message receiving done.Only available when UART_TRANSPARENT is defined. In this case, default value is 250ms.
#define UART_ID_LENGTH (4) 0/1/4 Optional UART ID length, which is related to the ID area in protocol. Only available when UART_PROTOCOL is defined. In this case, the default value is four bytes.
#define CAN_ID_LENGTH (0) 0/1/4 Optional CAN ID length, which is related to the ID area in protocol. In this case, default value is 0 bytes.
#define TRANSMIT_DATA_LENGTH (12) <=64 Size of data area. If the received message contains more data than this value, data loss can occur.
#define C2U_FIFO_SIZE (8) Size of CAN to Uart FIFO. Note the usage of SRAM.
#define U2C_FIFO_SIZE (8) Size of Uart to CAN FIFO. Note the usage of SRAM.
#define DEFAULT_UART_ORIGIN_ID (0x00) Default value for UART origin ID
#define DEFAULT_UART_DESTINATION_ID (0x00) Default value for UART destination ID
#define DEFAULT_CAN_ORIGIN_ID (0x00) Default value for CAN origin ID
#define DEFAULT_CAN_DESTINATION_ID (0x00) Default value for CAN destination ID