SPI

class wpilib.SPI(port)[source]

Bases: builtins.object

Represents a SPI bus port

Constructor

Parameters:port – the physical SPI port
class Port[source]

Bases: builtins.object

kMXP = 4
kOnboardCS0 = 0
kOnboardCS1 = 1
kOnboardCS2 = 2
kOnboardCS3 = 3
SPI.devices = 0
SPI.read(initiate, size)[source]

Read a word from the receive FIFO.

Waits for the current transfer to complete if the receive FIFO is empty.

If the receive FIFO is empty, there is no active transfer, and initiate is False, errors.

Parameters:
  • initiate – If True, this function pushes “0” into the transmit buffer and initiates a transfer. If False, this function assumes that data is already in the receive FIFO from a previous write.
  • size – Number of bytes to read.
Returns:

received data bytes

SPI.setChipSelectActiveHigh()[source]

Configure the chip select line to be active high.

SPI.setChipSelectActiveLow()[source]

Configure the chip select line to be active low.

SPI.setClockActiveHigh()[source]

Configure the clock output line to be active high. This is sometimes called clock polarity low or clock idle low.

SPI.setClockActiveLow()[source]

Configure the clock output line to be active low. This is sometimes called clock polarity high or clock idle high.

SPI.setClockRate(hz)[source]

Configure the rate of the generated clock signal. The default value is 500,000 Hz. The maximum value is 4,000,000 Hz.

Parameters:hz – The clock rate in Hertz.
SPI.setLSBFirst()[source]

Configure the order that bits are sent and received on the wire to be least significant bit first.

SPI.setMSBFirst()[source]

Configure the order that bits are sent and received on the wire to be most significant bit first.

SPI.setSampleDataOnFalling()[source]

Configure that the data is stable on the falling edge and the data changes on the rising edge.

SPI.setSampleDataOnRising()[source]

Configure that the data is stable on the rising edge and the data changes on the falling edge.

SPI.transaction(dataToSend)[source]

Perform a simultaneous read/write transaction with the device

Parameters:dataToSend – The data to be written out to the device
Returns:data received from the device
SPI.write(dataToSend)[source]

Write data to the slave device. Blocks until there is space in the output FIFO.

If not running in output only mode, also saves the data received on the MISO input during the transfer into the receive FIFO.

Parameters:dataToSend – Data to send (bytes)