The SPI class represents an SPI synchronous serial port. imp SPI buses are completely independent. Objects representing a given imp’s specific SPI buses are automatically instantiated at start-up and are accessed through the following object properties of the hardware object:
|imp||SPI 1||SPI 2||SPI 3||SPI 4||SPI 5|
The imp005’s second SPI bus is accessed via dedicated pins rather than GPIO, hence the slightly different nomenclature.
SPI always clocks data in both the read and write directions simultaneously — please see SPI Explained for more information. Most of the time, the data in one direction is simply filler, so the API behaves as if that filler data doesn’t exist: the spi.readblob() and spi.readstring() calls also write filler data, and the write call also reads and ignores filler data. Use spi.writeread() for those few occasions when the data in both directions is valid.
Currently, the imp must be the SPI master. Slave mode may be supported in a future firmware revision.
The imp does not directly model the chip-select or slave-select line mentioned in some descriptions of SPI. However, if needed, slave-select lines can be driven separately using a digital output and pin.write(). This means that the imp currently supports only “Motorola framing” (one chip-select pulse per transaction) and not “TI framing” (one chip-select pulse per byte).
The SPI object has the following member methods:
The SPI object also has the following deprecated member method, which should not be used in new code, but are documented here as an aid to understanding and migrating old code: