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

 

  1.   1
  2.   Abstract
  3.   Trademarks
  4. 1Introduction
    1. 1.1 Bridge between CAN and SPI
  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 SPI Receive and Transmit (Transparent Transmission)
    6. 3.6 SPI 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 SPI
    3. 5.3 Optional Configuration for CAN
    4. 5.4 CAN Bus Multinode Communication Example
  9. 6Summary
  10. 7References

SPI Receive and Transmit (Transparent Transmission)

In general, the SPI master controls the SPI communication, and the SPI slave cannot trigger slave-to-master communication. In this design, another IO is used. The IO pull-down of the slave notifies the master that there is information to be sent. The user can modify the pin or remove the IO function as required.

For SPI receive, there are three global variables defined in bridge_spi.c.

uint8_t gSpiReceiveGroup[SPI_RX_SIZE];
Custom_Element gSPI_RX_Element;
uint16_t gGetSpiRxMsg_Count;

The following is the process for the SPI master to receive data. An IO interrupt is used to detect the IO pull-down.

  1. In IO interrupt, call readSpiRxMsg() to send (SPI_TRANSPARENT_LENGTH) bytes to receive message from the SPI slave (SPI send and receive together).
  2. Call getSpiRxMsg_transparent() to store a message into gSpiReceiveGroup. Message receiving is finished when (SPI_TRANSPARENT_LENGTH) bytes are received.
  3. Call processSpiRxMsg_transparent() to extract data from gSpiReceiveGroup and store the data in gSPI_RX_Element.
  4. Put gSPI_RX_Element into gSpi2Can_FIFO.

The following is the process for the SPI slave to receive data

  1. Call getSpiRxMsg_transparent() to store message into gSpiReceiveGroup. Message receiving is finished when timeout occurs.
  2. Call processSpiRxMsg_transparent() to extract data from gSpiReceiveGroup and store the data into gSPI_RX_Element.
  3. Put gSPI_RX_Element into gSpi2Can_FIFO.

For SPI transmit, there are two global variables defined in bridge_spi.c.

uint8_t gSpiTransmitGroup[SPI_TX_SIZE];
Custom_Element gSPI_TX_Element;

The following is the process for SPI master and slave transmission.

  1. Obtain gSPI_TX_Element from gCan2Spi_FIFO.
  2. Call processSpiTxMsg_transparent() to obtain data from gSPI_TX_Element and store the data into gSpiTransmitGroup.
  3. Call sendSpiTxMsg() to transmit gSpiTransmitGroup through SPI. For the SPI slave, only (SPI_TRANSPARENT_LENGTH) bytes are sent.
  4. (SPI slave only) Use IO to trigger the master to read from the slave.