Skip to content

Latest commit

 

History

History
17 lines (11 loc) · 4.32 KB

SerialProtocols.md

File metadata and controls

17 lines (11 loc) · 4.32 KB

Serial Communication Protocols

Serial communication protocols designed for transmitting longer data messages with different applications in mind (e.g., one to one vs. one to many communication). In this short appendix document we will highlight 3 of them: universal asynchronous receive transmit (UART), inter-integrated circuit (I2C), and serial peripheral interface (SPI).

UART

While UART is remarkably simple to wire up and permits simultaneous bidirectional data transfer, there is no explicit understanding of transfer rates that is shared between each, hence the term “asynchronous” being a part of its name. Instead, both sides of a UART channel must have an agreed upon rate of data transfer in bits per second, referred to as the baud rate. Modules that communicate via UART will often have a pre-defined baud rate, that you as a designer must program your microcontroller to match in order to communicate. One of the most crucial drawbacks of UART is that it is a strictly point-to-point communication protocol, meaning it is designed for one device to communicate with only one other device.

I2C

For systems where you would like your MCU to communicate with multiple modules, without needing to wire up separate links for each module, the I2C and SPI protocols allow the creation of a serial bus. On a serial bus, many son, or peripheral, devices can communicate with a single mother, or controller, using the same data lines. I2C, like UART, only uses two wires: SDA, serial data, and SCL, serial clock. The SCL line allows the mother to explicitly set the data transfer rate, contrasted with UART, where both devices need to know the bit-rate beforehand. This simple wiring does come at the cost of data transfer being half duplex, meaning in one direction at a time. In addition, when initiating a data transfer on an I2C bus, the mother device must specify which device it is sending data to or requesting data from by first indicating the address of the intended son device.

SPI

The SPI protocol, on the other hand, simplifies the issue of addressing by breaking out a separate, son-select (SS) line for every son device (you may also see CS for chip-select). The mother then indicates which son device it is communicating with by pulling the son-select line for that son low. This advantage of simpler, faster addressing comes with the disadvantage of each additional son device requiring another wire, whereas an I2C bus is always only two wires. An SPI bus, on the other hand, requires a serial clock line, like I2C, in addition to two data lines for simultaneous bidirectional, or full duplex, data transfer, plus one son-select line for every son on the bus. Thus, SPI is significantly more complex to wire than both UART and I2C, but achieves the fastest data transfer of the three due to simple addressing and fast clock rates (typically in the range of a few MHz).

Usage in Embedded Systems

In a real embedded system, sensors and other peripherals that communicate via a serial protocol may be on the same board as the microcontroller, in which case the physical manifestation of the various data, clock, and select lines discussed above will be traces on a PCB. One example of this on the Nano 33 BLE Sense is the connection to the built-in IMU, the LSM9DS1, which the NRF52840 communicates with via an I2C bus. Some applications may require that sensors be off-board, in which case connection can be achieved via a cable assembly. The latter can also be useful in development as well, as there are several lines of sensor and actuator development boards that use standardized connectors to allow for plug-and-play, rapid prototyping. One such line that is particularly relevant for this course is the Grove system from SeeedStudio, as the Tiny Machine Learning Shield in your kit has 6 built-in Grove connectors. The 3 connectors on the right form an I2C bus that you can connect multiple sensors or actuators too.

Note: the Grove connectors on the shield supply 3.3V to the modules that you connect to them, while some Grove modules may require 5V to work properly. Before purchasing a module for use with the shield, make sure that it is designed to accept either 3.3V or 5V.