• Set up the data structure to operate the device.
  • Configure the SPI hardware.
  • Basic operation of the physical device, apart from IO.


An SPI Device can talk to multiple connected peripherals, selected via CS (chip select), and to each peripheral using a different configuration. The main configuration parameters of SPI are

  • serial clock rate (fsclk),
  • serial clock polarity and phase (cpol, cpha), and
  • data size (8 or 16 bits).

SPIdev.Device also provides parameter txShift value, ie. the “dummy” transmit data to receive data.1

SPIdev provides the usual" procedures Init, Configure, and Enable to get the SPI hardware up and running. The configuration of the GPIO pins and pads used – MOSI, MISO, SCLK, and CS – must be done by the client module or program.

If the chip select signal is to be operated via SIO (see section Chip Select Options (CS) in SPIrtc), this must be done by the client as well. SPIdev does not provide support for chip selection. See module RTCds3234.mod for an example.

In case a peripheral connected via SPI requires different configuration parameters than set up via SPIdev.Configure, a corresponding adjusted RunCfg can be derived, and switched to and from dynamically.

Currently, SPIdev supports two such configuration parameter adaptations:

  • serial clock rate
  • txShift value

Other adjustable parameters may be added in the future. For example, some SPI-driven displays expect so called commands to be sent as 8 bit values, but allow to transfer data as 16 or 32 bits. A dynamic switch between data sizes could be useful (the RP2040’s SPI device allows data sizes between 4 and 16 bits).


  • The MCU has two equal SPI devices, each supporting multiple external peripherals connected in parallel (MOSI, MISO, SCLK), selected via chip select (CS), which is active low.
  • See also: SPIdata.mod, example program SPIrtc2



  1. Many SPI peripherals don’t care about this value, but some do, such as SD cards. For the DS3234 we use values that display well on an oscilloscope. 0H or 0FFH would not. ↩︎