SPI master clock and data (SCLK, MOSI and MISO)
This resource implements Serial Peripheral Interface (SPI) master clock and data lines, which allows Sensor Controller task code to perform SPI data transfers.
The interface consists of the following signals:
The pins are mapped in the I/O Mapping Panel.
One or more usages of the SPI Chip Select resource must be used to implement chip select (CSN).
General features:
It is assumed that the SPI signals are not shared with another, external SPI master. The SCLK and MOSI lines are driven while CSN is deasserted to prevent these lines from floating. The MISO line can be configured as no pull, pull-up or pull-down. Note that the MISO input buffer is disabled while CSN is deasserted, and will not cause leakage if the pin is left floating in this state (with no pull).
// Read the accelerometer spiCfg(SPI_POL0_PHA0, 6); spiBegin(AUXIO_SPI_CSN_ACCEL); spiTx8bit(0x42); spiRx16bit(output.x); spiRx16bit(output.y); spiRx16bit(output.z); spiEnd(AUXIO_SPI_CSN_ACCEL);
Name | Description |
---|---|
SPI_POL0_PHA0 | First edge of SCLK is rising, MOSI/MISO sampled at first edge of SCLK |
SPI_POL0_PHA1 | First edge of SCLK is rising, MOSI/MISO propagated at first edge of SCLK |
SPI_POL1_PHA0 | First edge of SCLK is falling, MOSI/MISO sampled at first edge of SCLK |
SPI_POL1_PHA1 | First edge of SCLK is falling, MOSI/MISO propagated at first edge of SCLK |
None.
Prototype: spiCfg(polPha, div)
Configures the SPI Master peripheral before operation.
Prototype: spiClearMosi()
Clears the SPI MOSI pin (the pin is set to low level).
Prototype: spiRx16bit(rxValue)
Transmits two bytes, 0x0000, over SPI. The received bytes are stored, first byte in value[15:8] and second byte in value[7:0].
Prototype: spiRx8bit(rxValue)
Transmits a single byte, 0x00, over SPI. The received byte is stored.
Prototype: spiSetMosi()
Sets the SPI MOSI pin (the pin is set to high level).
Prototype: spiTx16bit(txValue)
Transmits two bytes over SPI.
The procedure returns immediately. Any following SPI operation, including spiEnd(), will wait for the operation to finish.
Prototype: spiTx8bit(txValue)
Transmits a single byte over SPI. The received byte is ignored.
The procedure returns immediately. Any following SPI operation, including spiEnd(), will wait for the operation to finish.
Prototype: spiTxRx16bit(txValue; rxValue)
Transmits and receives two bytes over SPI.
Prototype: spiTxRx8bit(txValue; rxValue)
Transmits and receives a single byte over SPI.