Maximum number of SPI devices

I would appreciate the community’s help on finding out the maximum umber of SPI devices that ca be connected to a Photon?

For example, can I have both an SD card and an SPI screen?

Thanks in advance.

In theory you can connect as many devices as you want to a single SPI bus. And the Photon/Electron have two SPI busses, one on the A pins and one on the D pins.

Each SPI device on the SPI bus has a unique chip select (CS or SS), this is how the SPI device knows it’s the one to respond. As long as each SPI device has a separate CS line, they can be on the same bus. Thus there is a limit based on the number of available GPIO pins you have.

And there’s an important caveat: There are several SPI parameters including the mode, bit order, and speed. Different SPI devices may require different settings. The problem is that some libraries do not take this into account and only change the settings once at startup. Thus the devices won’t work properly when shared with a bus using devices with different settings. This can generally be fixed by editing the library or manually changing the SPI settings before accessing the SPI device.