Connect multiple SPI displays to a single controller
SPI Definition:
The Serial Peripheral Interface (SPI) is a
synchronous serial communication interface specification used for
short-distance communication,
primarily in embedded systems. The
interface was developed by Motorola in the mid-1980s.
It is widely
known for small distance communication, maximum distance for SPI
communication is limited to below 10m.
And the distortion in data is
directly proportional to the distance.
"If you want to connect N number of devices you only need 3+N number of pins"
Connecting multiple Display modules in Arduino is always sounds impossible , as it is limited by SPI pins .But the fact is it is as simple as connecting one single SPI device - yes!, If connecting single SPI device is easy for you then connecting multiple SPI devices to a controller is just repeating the same work N times.
The figure below shows the generalized pin-out of SPI devices
All SPI devices will be having these 4 pins , MOSI,MISO,CLK,CSMOSI:
Master out slave in
MISO:
Master in slave out
CLK:
Clock signal
CS/SS:
Chip select
MOSI ,MISO are communication lines like RX,TX lines(in which the
master(controller) and slave(SPI display or device) establish
communication
CLK/SCLK is the clock signal for synchronization.
CS- Is the one who plays the leading roll here. It is the one which initiate/trigger the communication
So we can use this CS pin to solve the SPI pin limitation issues in the micro controllers .
i.e By putting logic in CS pin we can share the MISO,MOSI pins with multiple devices.
The figure below shows the example connection diagram
yaah, we are just shorting it!
"sharing is caring👻"
If you want to connect N number of devices you only need 3+N number
of pins
All MISO lines are shorted together and connected to MISO supported pin
of our micro-controller.
All MOSI lines are shorted together and connected to MOSI supported pin of our micro controller.
All CLK/SCLK lines are shorted with Clk pin in micro-controller
And CS/SS pins are connected to individual pins of the micro-controller .
now the CS pin will decide which slave/SPI device should communicate with the micro-controller.
To send data from the master device to the slave device, you first need to set the SS/CS pin on the
master device to LOW
, and keep it
LOW
for the duration of the data exchange. This prepares
the slave
device to send or receive data. Once the SS/CS pin is
LOW
, the master can send data over the MOSI line
and simultaneously produce clock pulses from the SCLK pin.