SPI is a synchronous communication method to communicate between devices.
What does synchronous mean?
In synchronous communication method, bit timing (or we can say sampling of bytes) is controlled by a clock signal. For instance, if bit 1 wants to be transmitted, starting and ending points of this bit are controlled by rising or falling edge of clock pulse. Check two images below, these are illustration of asynchronous and synchronous method respectively.
In this SPI, there should be master device which will usually be your MCU. Master is source of clock signal and it will control most of communication rules such us max speed of communication line.
While master sends data to slave, it uses MOSI line which stand for Master Out Slave In. On the other way there is MISO line which stand for Master In Slave Out and it is used to transmit from slave to master. Also it is best practice to have common GND between devices.
In this point you can come up with the question "What if we have more than one slave which are connected to single master. How can we prevent data congestion and/or corrupt in the MISO and MOSI line?". Answer is quite easy. There is CS (Chip Select, sometimes refer as SS which stand for Slave Select) pin each slave devices. When CS pin is pulled to GND, chip will be enabled to start communication. Otherwise, if it is pulled HIGH, chip is disabled and will not have communication with master device.
Also it might be your second question that how do we decide which edge of clock signal should we choose? Well, it will be defined by your slave manufacturer and always you can find this information on slave device datasheet under SPI communication section.
Comments
Post a Comment