I read in few places, one of them is this, that one of the main differences between UART and SPI is that the former is a type of hardware and the latter is a protocol.
I'm having hard time to fully grasp this notion. This is briefly what I got so far from the reading material I found googling, embedded with some questions:
UART is a piece of hardware used to communicate between two components. The UART converts parallel data that it receives from a data bus into a serial stream of bits that are transferred across only one wire and vice versa. A UART uses only 2 wires - one for receiving and one for transmitting. The rest of the details aren't important for the manner of this discussion.
SPI is a synchronous (since it uses a clock) communication protocol used between devices.
This protocol uses 4 wired (if only one slave is present):
- MOSI (Master Out/Slave In) - used to transmit data from master to slave
- MISO (Master In/Slave Out) - used to transmit data from slave to master
- SCLK - (Clock) - used to synchronize the data transmission.
- SS/CS - (Slave Select/Chip Select) - When pulled low, signals the chip to communicate.
Unlike UART, it transfers bits in a stream not divided to packets (Here confusion begins - it's compared to UART). Devices communicating via SPI are in master-slave relationship. Master is the controlling device - usually a microcontroller - while the slave - usually something like a display, sensor or memory chip - takes instructions from the master. (Sanity check - When we say that the master controls the slave, we merely mean the selection of the slave by the SS/CS wire and the clock signaling?)
Differences between UART and SPI
- Number of wires - UART uses 2, SPI uses at least 4
- No start/stop bits - data is sent continuously without interruptions.
- Number of devices - UART can have only 2, SPI can virtually connect unlimited number of slaves to one master
- Hardware vs Protocol - UART is a type of hardware while SPI is a protocol.
Finally - the question
What I'm mainly confused about is this last difference - Hardware vs Protocol. It seems that these two communication schemes are compared side-to-side in the same parameters (Number of pins, start/stop bits, Speed, etc.) - you can't compare 2 essentially different entities based on the same parameters right?
Is the difference is that UART is a dedicated piece of hardware and SPI uses general GPIOs of the microcontroller?