Site icon Iotguider

Using SPI (Serial Peripheral Interface) in Arduino

Using SPI in Arduino

Learn using SPI in Arduino. SPI (Serial Peripheral Interface), establishes communication between multiple peripheral devices or microcontrollers. The SPI interface bus exchanges data between microcontrollers and small peripherals such as shift registers, sensors, and SD cards. It uses the different clock and data lines along with a select line to choose to communicate with which device.

Generally, there are three lines common to all the devices, MISO (Master In, Slave Out) and MOSI (Master Out, Slave In). For device selection, we use SCK Clock Line and fourth one SS (Slave Select). SS pin will switch devices when connecting multiple devices. Now let’s see how SPI Communication in Arduino works.

Different library Functions of SPI in Arduino

SPI.begin()
SPI.usingInterrupt(interrupt)



SPI.beginTransaction(SPISettings(clock speed, MSBFIRST, SPI_MODE0))
digitalWrite(SSpin, level)
SPI.transfer(data)
SPI.endTransaction()



Circuit Time




Code Time

Master Arduino for SPI Communication Code

Slave Arduino for SPI Communication Code



Upload the code to Arduino

Thus now you can Upload the above-given code to two Arduino Boards and it will transfer “Hello World!” using SPI Communication.

Learn about uploading code to Arduino Boards.

Exit mobile version