![FTDI FT51A Скачать руководство пользователя страница 35](http://html1.mh-extra.com/html/ftdi/ft51a/ft51a_application-note_2341158035.webp)
Application Note
AN_289 FT51A Programming Guide
Version 1.0
Document Reference No.: FT_000962 Clearance No.: FTDI# 483
34
Copyright © 2015 Future Technology Devices International Limited
| 1 << 0x03); // Set SS high, i.e. deactivate it
2.3.12.2
Polled Interface
The SPI Master device is used as a polled interface sending a command to an SPI slave and
reading a response.
1.
Enable the Slave Select method required.
2.
For each byte of data:
a.
Write a byte to send to the slave into the
SPI_MASTER_TX_DATA
register.
b.
Poll the
SPI_MASTER_TRANSFER_PENDING
register until the pending bit clears.
c.
Read a byte from the slave from the
SPI_MASTER_RX_DATA
register.
3.
Disable Slave Select.
The polled interface is useful for low-speed transactions where there are small amounts of data to
receive from, or send to, the SPI slave. It is particularly useful when there are decisions to be
taken depending on the contents of data returned from the SPI slave.
2.3.12.3
Interrupt Interface
An interrupt handler can be employed to speed up transmission and reception of multiple bytes of
data. This method requires the code to send the first byte of data to the SPI slave and an interrupt
handler routine to send subsequent bytes of data. The interrupt handler will also receive the data
returned from the SPI slave.
To setup an interrupt routine:
Clear the
tx_done_int
bit in the
SPI_MASTER_INT
register.
Enable the interrupt in the
tx_done_ien
in the
SPI_MASTER_IEN
register.
Initialise the buffer to transmit and buffer to receive data for use by the interrupt handler
routine.
o
Enable the Slave Select method required.
o
Write the first byte of data to the
SPI_MASTER_TX_DATA
register.
o
Wait for the interrupt handler to signal that the transfer is complete.
o
Disable Slave Select.
o
Within the interrupt handler:
Check for
tx_done_int
bit in the
SPI_MASTER_INT
register to be set and
tx_done_ien
in the
SPI_MASTER_IEN
register to be set.
Read a byte of data from the slave from the
SPI_MASTER_RX_DATA
register
and place it in the receive buffer.
Clear the
tx_done_int
bit in the
SPI_MASTER_INT
register.
If there is data still to transfer, write the next byte of the transmitting buffer to the
SPI_MASTER_TX_DATA
register. If the transfer is complete, signal, transfer complete.
This method is useful for most transfers of data to and from an SPI slave. It is still under program
control so decisions on data flow can be made within the interrupt handler. It is, however,
recommended to have a minimum of code in any interrupt handler. An example Interrupt Service
Routine is presented below.
//ISR
void SPIM_interrupt_handler()
{
READ_IO_REG(0x54, SPIM_interrupt); //SPI_MASTER_STAT_1
if(SPIM_interrupt & (0x1<<3)) //Check for RX_FULL interrupt
{
SPIM_num_bytes_tx--;
READ_IO_REG(0x52, *SPIM_MISO_buf); //SPI_MASTER_DATA_RX_ADDR_1