What are the use case scenarios for SPI blocks when developing a Simulink application for a TI C2000 platform?

28 visualizaciones (últimos 30 días)
What are the use cases for SPI blocks such as "SPI Master Transfer", "SPI Transmit", and "SPI Receive" blocks when developing a Simulink application for a TI C2000 board? 

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 24 de En. de 2025
Editada: MathWorks Support Team el 31 de En. de 2025
There are 3 different blocks supported as part of SPI module support under the TI C2000 Support Package: 
  1. SPI Master Transfer block 
  2. SPI Transmit block 
  3. SPI Receive block 
SPI Master Transfer block:
Under the hood, this block works as follows: Send word -> Wait -> Read word -> Proceed for next word.
Loop this sequence until all data words that are input to the block are done.
This essentially means the block works in blocking mode. That is, let’s say if there are five bytes (Note: "bytes" is used to make the explanation simple, it is basically "n" bits per transfer) that needs to be sent, the block sends and reads on a per-byte basis in a loop, effectively blocking the execution until all the bytes are done. 
The purpose of this block is to quickly set up a model and enable the C2000 controller (the SPI controller device) to communicate with SPI peripheral devices like EEPROM where the SPI interface (read/write) is standardized via a list of commands. The main disadvantage of this way is the inefficient usage of the CPU.
One additional option is provided in the "SPI Master Transfer" block called the "Register address" field. This field can hold the command value (CMD) + Register address (REGISTER). The user will have to then provide the DATA externally to the block (via input port) making it (CMD+REGISTER+DATA) sequence to be sent to the peripheral device. 
Please refer to the shipping example "c28x_spi_eeprom" for more details on the use case.  
Note: As can be seen, an "SPI Master Transfer" block is not an efficient way to handle the data transaction. It blocks the CPU and this block cannot be run in an interrupt context. Running in an interrupt context is not possible as the block reads the data from FIFO every time a byte is transmitted. Hence this block is supposed to be used by novice users who are not comfortable with complex blocks like "SPI Transmit" and "SPI Receive" blocks. The latter can be configured for FIFO depth, FIFO interrupts providing an efficient way to do SPI communication.
SPI Transmit and Receive block:
  
When using these blocks, we can configure the FIFO depth and FIFO interrupt. This gives the user flexibility to implement efficient system design. When we have multiple data bytes to send, we need not keep the CPU busy for the same. The SPI Transmit block would write all the input data bytes to the Transmit FIFO buffers. The SPI module would then send the data bytes independent of CPU from these buffers. Thus we are releasing the CPU for other tasks once the SPI Transmit block updates the FIFO buffers. When the data transfer is done, an interrupt for the FIFO empty (or the configured Transmit FIFO length) can be generated to copy a fresh set of data to FIFO buffers. 
Similarly, for the receive operation, an interrupt for the FIFO full (or the configured Receive FIFO length) can be generated to read the data values from the Receive FIFO buffers using the "SPI Receive" block. For more details on the use cases, including the documentation page, execute the following command in the MATLAB command window:
>> web(fullfile(docroot, 'supportpkg/texasinstrumentsc2000/ug/using-spi-to-read-write-data-spi-eeprom.html'))
Please follow the below link to search for the required information regarding the current release:

Más respuestas (0)

Categorías

Más información sobre C2000 Microcontroller Blockset en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by