Hardware Communication Protocols¶
Microcontrollers can talk between each other in a variety of ways. Described here are the most popular hardware protocols that can be implemented on nearly all microcontrollers.
- Fast communication (1kHz to 200kHz+)
- Usually two devices
- Both devices can send data to the other without prompt
- Can be used over short and medium distance
- Error checking possible through parity bit
- Simple interface to USB, RS-232, RS-422, RS-485
- UART: 2-wire (Rx, Tx)
Serial communication is useful for a dedicated communication line between two devices. It sends data in packets of usually 8-bits. Each wire is unidirectional but with Rx and Tx, data can be sent in both directions. Both devices must be set to read and write data at the same speed (baud rate). If working with a hardware UART, the software required is very simple.
- Medium speed (up to 100kHz, with fast I2C up to 400kHz)
- Up to 127 devices (more with 10-bit addressing)
- Master-slave operation: Master can send and request data from slaves at any time, but slaves must be prompted to send information
- Short distance (limited by bus capacitance)
- 2-wire: SDA (data) and SCL (clock)
- Multiple masters allowed (arbitration prevents two masters from driving SDA and SCL simultaneously)
- Clock stretching allows Slave to wait before sending data
- ACK bit indicates if data was received
I2C is a useful protocol for a large network of devices that all communicate on the same two wires. However, software is required to control the I2C hardware module in a microcontroller.
Serial Peripheral Interface (SPI)¶
- Medium to High speed
- 2+ devices, limited by slave enable lines
- Short to medium distance
- 3+ wires: MOSI (Master out Slave in), MISO (Master in Slave out), SCLK (clock), enable line for each slave (not necessary for master-slave operation)
- Master-slave operation
SPI is essentially one shift register on each device, so the master shifts data onto the MOSI line, and reading data into the shift register from the MISO line. SPI is useful for two or a limited number of devices, since each slave must have an enable line.
RS-232 is a version of Serial communication designed for long distance operation. It is not directly compatible with UARTs found in microcontroller, but instead needs a dedicated RS-232 to TTL converter.
RS-485 is a version of Serial communication designed for long distance operation with multiple devices. It is not directly compatible with UARTs found in microcontrollers, but instead needs a dedicated RS-485 to TTL converter