SPI
The SPI bus is used for reading and writing sensors, memory devices, etc. Although it uses more pins than I2C, it is often used for devices that require high-speed transfer.
Please refer to the Samp_SPI sample.
When using the SPI bus, only enough SPI select pins are allocated for the required device. The pins are allocated in order, starting with the SEISEL0 pin.
The following are some examples of initialization and read/write operations; SPI also allows simultaneous write and read operations.
A common example when acquiring data from a sensor is the procedure of sending a command followed by getting the result.
Initialize SPI (start using device)
Enable select pin for SPI
SPI Transfer 1 (8 bits), intended for transmission.
SPI transfer 2 (16 bits), intended for reception.
You should always wait for polling (while(bAHI_SpiPollBusy());
) on each transfer.
functions
vAHI_SpiConfigure()
This function initializes the SPI device and makes it available, and calls vAHI_SpiDisable()
to release it.
At least one select pin, SPISEL0, is assigned exclusively to SPI. In other words, when using SPI, SPISEL0 (DIO19) cannot be used for any other purpose.
The values of bLsbFirst
, bPolarity
, bPhase
, and u8ClockDiviser
should be determined from the datasheet of the device to be connected.
Relationship between SPI Mode and bPolarity, bPhase.
vAHI_SpiSelect()
Activate select pins.
vAHI_SpiStop()
and vAHI_SpiSelect(0)
are the same call.
vAHI_SpiStartTransfer()
Start SPI transfer. The transfer starts immediately after this function is called, but the control is returned without waiting for the transfer to finish. It waits for the end of transfer by bAHI_SpiPollBusy()
described below.
bAHI_SpiPollBusy()
Waiting for polling of SPI transfer, while TRUE means SPI transfer is in progress.
u32AHI_SpiReadTransfer32()
Called after the SPI transfer is completed, this function reads the received data (SPIMISO) at the time of transfer. The read data is right justified to the LSB side.
最終更新