A Serial Peripheral Interface (SPI) bus is a serial communication device that uses up to four, usually three, conductors. For data receiving, one conductor is used, one for data sending, one for synchronization and one for choosing a computer to communicate with. It is a complete duplex link, which means that the data is simultaneously sent and received. In the I2C communications system, the actual baud rate is greater than that.
SPI uses the following four wires −
SCK − This is the serial clock driven by the master.
MOSI − This is the master output / slave input driven by the master.
MISO − This is the master input / slave output driven by the master.
SS − This is the slave-selection wire.
connect the two Arduinos as showen to start communicate together using SPI communication
including the SPI library inside the code (SPI.h)
assign slave select pin (SS) to pin 10
configure the baudrate to be 9600 bit/sec (recommend ).
initialize the SPI communication by calling the function (SPI.beging();)
define the slave selector pin as output pin in the code
trigger the slave selector pin to be low which make the master able to take with the slave board
waiting for 100 millisecond
define a character variable and assign it to (SPI.trasnfer) function to send the character ('a') to the slave
waiting for 1 second
then assign the variable to send the character "s" to the slave
then trigger again the selector pin bach to high to stop the communication
waiting for 100 millisecond
including the SPI library inside the code (SPI.h)
assign slave select pin (SS) to pin 10
make a bool variable called flag and assign it to be false
make a variable called s_recv which will receive the coming data in the serial
define the led to be pin 13 in the slave which is in the Uno board by default
define SW (switch ) which will be connected to a switch pin 3
define the led to be an output pin
define SW to be an input pin
define MISO to be an output pin which will send the data to the master
enabling the interrupts function in the slave to make it able to receive the data
receiving the data from the master and get the data from the SPDR register then save it in the variable s_recive
make if condition to check if the coming data from the master which saved in the variable s_recev IS the character "a" then trigger the led to high
if the character in the variable is "S" then close the led
What I learned this week is...
UART serial communication
i2c serial communication
Spi serial communication
the difference between serial and parallel communication
how to establish serial communication between master and slave board