13. Serial peripheral interface(SPI)¶
SPI can support different mode
general 3 wire mode, 1-bit clock in/out, 1-bit data output, 1-bit data input.
2 wire mode, 1-bit clock in/out, 1-bit data output or input.
2 data bus mode, 1-bit clock in/out, 2-bit data output or input.
SPI Normal 1bit-Mode Operation Flow:
Set 3-wire mode or 2-wire mode and select the pin map.
Select RXSEL for Transmit or receive.
Configure clock frequency .
Select one of the four timing mode.
Enable SPI module by setting SPIEN ‘1’.
Set SPIIE ‘1’ if needed.
Write data to SPIBUF to kick-start the process.
Wait for SPIPND to change to ‘1’, or wait for interrupt.
Read received data from SPIBUF if needed.
Go to Step 8 to start another process if needed or turn off SPI1by clearing SPIIE and SPIEN.
SPI Normal multi-bit-Mode Operation Flow:
Set data bus width(bus 2) and select the pin map.
Select RXSEL for Transmit or receive.
Configure clock frequency .
Select one of the four timing mode.
Enable SPI module by setting SPIEN ‘1’.
Set SPIIE ‘1’ if needed.
Write data to SPIBUF to kick-start the process.
If data bus width are 2 bit, write SPIBUF twice kick-start the transmission.
However, when receive data, only need write once to kick-start receive process.
Wait for SPIPND to change to ‘1’, or wait for interrupt.
Read received data from SPIBUF if needed.
Go to Step 8 to start another process if needed or turn off SPI by clearing SPIIE and SPIEN.
SPI DMA Mode Operation Flow:
Set IO in the correct direction and data width mode.
Select RXSEL for DMA direction.
Configure clock frequency .
Select one of the four timing modes.
Enable SPI module by setting SPIEN to ‘1’.
Set SPIIE ‘1’ if needed.
configure SPI1DMAADR.
Write data to SPI1_DMACNT to kick-start a DMA process.
Wait for SPIPND to change to ‘1’, or wait for interrupt.
Go to Step 8 to start another DMA process if needed or turn off SPI1 by clearing SPI1EN.