12.4.4 SPI 3-Wire Mode Code Examples
In addition to the normal SPI initialization, to configure the SPI module for 3-wire mode, the TRIWIRE bit
(SPIPRI.0) must be set to 1. After initialization, there are several considerations to take into account when
transmitting and receiving data in 3-wire master and slave mode. The following examples demonstrate these
considerations.
In 3-wire master mode, SPICLKx, SPISTEx, and SPISIMOx pins must be configured as SPI pins (SPISOMIx
pin can be configured as non-SPI pin). When the master transmits, it receives the data it transmits (because
SPISIMOx and SPISOMIx are connected internally in 3-wire mode). Therefore, the junk data received must be
cleared from the receive buffer every time data is transmitted.
Example 12-4. 3-Wire Master Mode Transmit
Uint16 data;
Uint16 dummy;
SpiaRegs.SPICTL.bit.TALK = 1; // Enable Transmit path
SpiaRegs.SPITXBUF = data; // Master transmits data
while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) {} // Waits until data rx’d
dummy = SpiaRegs.SPIRXBUF; // Clears junk data from itself
// bc it rx’d same data tx’d
To receive data in 3-wire master mode, the master must clear the TALK (SPICTL.1) bit to 0 to close the transmit
path and then transmit dummy data in order to initiate the transfer from the slave. Because the TALK bit is 0,
unlike in transmit mode, the master dummy data does not appear on the SPISIMOx pin, and the master does not
receive its own dummy data. Instead, the data from the slave is received by the master.
Example 12-5. 3-Wire Master Mode Receive
Uint16 rdata;
Uint16 dummy;
SpiaRegs.SPICTL.bit.TALK = 0; // Disable Transmit path
SpiaRegs.SPITXBUF = dummy; // Send dummy to start tx
// NOTE: because TALK = 0, data does not tx onto SPISIMOA pin
while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) {} // Wait until data received
rdata = SpiaRegs.SPIRXBUF; // Master reads data
In 3-wire slave mode, SPICLKx, SPISTEx, and SPISOMIx pins must be configured as SPI pins (SPISIMOx
pin can be configured as non-SPI pin). Like in master mode, when transmitting, the slave receives the data it
transmits and must clear this junk data from its receive buffer.
Example 12-6. 3-Wire Slave Mode Transmit
Uint16 data;
Uint16 dummy;
SpiaRegs.SPICTL.bit.TALK = 1; // Enable Transmit path
SpiaRegs.SPITXBUF = data; // Slave transmits data
while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) {} // Wait until data rx’d
dummy = SpiaRegs.SPIRXBUF; // Clears junk data from itself
Serial Peripheral Interface (SPI)
SPRUH18I – JANUARY 2011 – REVISED JUNE 2022
TMS320x2806x Microcontrollers
777
Copyright © 2022 Texas Instruments Incorporated
Содержание TMS320 2806 Series
Страница 2: ......