SLAAEN5 February 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
All the configurable parameters are defined in user_define.h, which are listed in Table 3-3.
For SPI, both transparent transmission and protocol transmission are supported in this example, switching by defining SPI_TRANSPARENT or SPI_PROTOCOL.
In transparent transmission, users can configure the timeout for the SPI slave to detect one SPI message receiving done. Users can also configure the default data length(SPI_TRANSPARENT_LENGTH) for the message from the SPI slave to the SPI master. Table 3-2 lists the number of bytes for receiving or sending with different modes.
In protocol transmission, users can configure the ID length for different formats. Note that there is a fixed 2-byte header(0x55 0xAA) and one byte of data-length. To modify the format more, users can modify the code directly.
#define SPI_TRANSPARENT
#ifdef SPI_TRANSPARENT
/* The format of SPI:
* Transparent transmission - Data1 Data2 ...*/
/* data length for SPI master receiving or SPI slave transmitting*/
#define SPI_TRANSPARENT_LENGTH (8) //need be <= TRANSMIT_DATA_LENGTH
#define SPI_TIMEOUT (0x4000) //timeout 250ms
#else
/* The format of SPI:
* if SPI_ID_LENGTH = 4, format is 55 AA ID1 ID2 ID3 ID4 Length Data1 Data2 ...
* if SPI_ID_LENGTH = 1, format is 55 AA ID Length Data1 Data2 ...
* if SPI_ID_LENGTH = 0, format is 55 AA Length Data1 Data2 ...*/
//#define SPI_ID_LENGTH (0)
//#define SPI_ID_LENGTH (1)
#define SPI_ID_LENGTH (4)
#endif
| Parameter | SPI Interface: Master | SPI Interface: Slave | ||
|---|---|---|---|---|
| How many bytes are received? | How many bytes are sent? | How many bytes are received? | How many bytes are sent? | |
| Protocol Transmission | (2+SPI_ID_LENGT+1+Length) bytes | (2+SPI_ID_LENGT+1+Length) bytes | (2+SPI_ID_LENGT+1+Length) bytes | (2+SPI_ID_LENGT+1+Length) bytes |
| Transparent Transmission | (SPI_TRANSPARENT_LENGTH) bytes | (Length) bytes | Timeout identify the end of message | (SPI_TRANSPARENT_LENGTH) bytes |
For CAN, ID or 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)
| Parameter | Optional value | Description |
|---|---|---|
| #define SPI_TRANSPARENT | Define / Not define | Enables the SPI transparent transmission. |
| #define SPI_PROTOCOL | Define / Not define | Enables the SPI protocol transmission. |
| #defineSPI_TRANSPARENT_LENGTH (8) | The default data length for message from the SPI slave to the SPI master. Only available when SPI_TRANSPARENT is defined. In this case, default value is eight bytes. | |
| #define SPI_TIMEOUT (0x4000) | Timeout = SPI_TIMEOUT / 32768 s | Timeout to indicate one SPI message receiving done.Only available when SPI_TRANSPARENT is defined. In this case, default value is 250ms. |
| #define SPI_ID_LENGTH (4) | 0/1/4 | Optional SPI ID length, which is related to the ID area in protocol. Only available when SPI_PROTOCOL is defined. In this case, 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, the default value is 0 byte |
| #define TRANSMIT_DATA_LENGTH (12) | <=64 | Size of data area. If the received message contains more data than this value, it can result in data loss |
| #define C2S_FIFO_SIZE (8) | Size of CAN to SPI FIFO. Note the usage of SRAM. | |
| #define S2C_FIFO_SIZE (8) | Size of SPI to CAN FIFO. Note the usage of SRAM. | |
| #define DEFAULT_SPI_ORIGIN_ID (0x00) | Default value for SPI origin ID | |
| #define DEFAULT_SPI_DESTINATION_ID (0x00) | Default value for SPI 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 |