Sensor Controller Studio

Serial Interfaces : SPI Data Transfer

Description

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).

Examples
Accelerometer Polling

// 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);

Constants

NameDescription
SPI_POL0_PHA0First edge of SCLK is rising, MOSI/MISO sampled at first edge of SCLK
SPI_POL0_PHA1First edge of SCLK is rising, MOSI/MISO propagated at first edge of SCLK
SPI_POL1_PHA0First edge of SCLK is falling, MOSI/MISO sampled at first edge of SCLK
SPI_POL1_PHA1First edge of SCLK is falling, MOSI/MISO propagated at first edge of SCLK

Global Variables

None.

Procedures
spiCfg

Prototype: spiCfg(polPha, div)

Configures the SPI Master peripheral before operation.

Parameter value(s)

spiClearMosi

Prototype: spiClearMosi()

Clears the SPI MOSI pin (the pin is set to low level).

spiRx16bit

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].

Return value(s)

spiRx8bit

Prototype: spiRx8bit(rxValue)

Transmits a single byte, 0x00, over SPI. The received byte is stored.

Return value(s)

spiSetMosi

Prototype: spiSetMosi()

Sets the SPI MOSI pin (the pin is set to high level).

spiTx16bit

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.

Parameter value(s)

spiTx8bit

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.

Parameter value(s)

spiTxRx16bit

Prototype: spiTxRx16bit(txValue; rxValue)

Transmits and receives two bytes over SPI.

Parameter value(s)

Return value(s)

spiTxRx8bit

Prototype: spiTxRx8bit(txValue; rxValue)

Transmits and receives a single byte over SPI.

Parameter value(s)

Return value(s)