Download UM10326

Transcript
UM10326
NXP Semiconductors
Chapter 21: LPC32x0 SPI master interface
write part of the register delivers data to the shift register. The size of the data frame to be
transferred is determined by the bitnum field in the SPIn_CON register. The clock of the
shift register is based on the output of the SPI clock generator. The bits of the SPIn_DAT
write register are shifted out on SPIn_DATIO or the bits on SPIn_DATIN are shifted into
the shift register (depending on the rxtx bit in SPIn_CON).
Sending data is accomplished by writing the data to be sent to the SPIn_DAT register,
which is copied to the shift register. Data is clocked out on SPIn_DATIO. SPIn_DAT may
be written with new data while the previous data is being shifted out. An end of transfer
interrupt is always generated after bitnum+1 SPIn_CLK clock cycles, if the interrupt is
enabled via the inteot bit in the SPIn_IER register.
To read data, the SPI can be started by doing a dummy read or dummy write to
SPIn_DAT. Received data may be read from SPIn_DAT after bitnum+1 SPI clock cycles.
A data read sequence can be stopped by setting the shift_off bit in the SPIn_CON
register. Setting shift_off is not necessary if the SPI interface is turned off prior to reading
the SPIn_DAT register for the last time.
4.2 Block transfers
A block transfer on the SPI can be used to transfer a number of frames. For examples,
these could be pages of data to or from an external SPI memory device. The SPIn_FRM
register contains the number of consecutive SPI frames to transfer. The threshold
interrupt should be enabled if the number of frames exceeds the FIFO size. The FIFO
pointer controls the read or write actions to the FIFO and generates an interrupt request if
the number of entries falls below the threshold in transmit mode or rises above the
threshold in receive mode.
The data transfer is only stopped if the receive FIFO is full during receive mode or the
transmit FIFO is empty during transmit mode. In this case the transfer will continue after
software reads or writes data, until the frame count reaches zero. At that point, the end of
transfer interrupt is flagged.
A block transfer can be configured as follows.
•
•
•
•
Check that the FIFO is empty and no transfer is running (SPIn_STAT).
Define the SPI frame size (the bitnum field in SPIn_CON).
Load the SPIn_FRM register with the number of SPI frames to be transferred.
Enable the threshold interrupt if required.
The master can initiate the transfer as follows.
• Read the SPIn_DAT register if a block should be transferred from the external device.
• Write the data word of the first SPI frame to the SPIn_DAT register if a block should be
transferred to the external device. This frame is included in the value of SPIn_FRM.
Every time a threshold interrupt is asserted, software must read or write data from
SPIn_DAT to maintain a continuous data transfer on the interface. After the complete
block is transferred, the end of transfer interrupt is asserted. If there are still entries in the
FIFO at that point, they should be read by the software.
UM10326_1
User manual
© NXP B.V. 2009. All rights reserved.
Rev. 1 — 18 February 2009
482 of 723