I’ve recently found myself funemployed with another month or so free, so I’m resuming this article series. I’ve been focusing on rebuilding core competence in a couple targeted technologies, and so I’ll be using this time to describe some of the work there.
Before I dive into specifics, we should talk about the idea of serial communications. This often is used to mean the serial port, which is actually a UART (Universal Asynchronous Receiver / Transmitter). Really, though, serial just means sending data sequentially (e.g. one bit at a time) and there are a few technologies to consider, although the term will generally refer specifically to UARTs. The three we’ll be looking at are UARTs, the two-wire interface (or I²C), and the serial peripheral interface (SPI). It’s helpful to place these in context:
- UART is a communications protocol between two peers. Electrically, the connections are very simple: you need a transmit (TX) pin and a receiver (RX) pin. The TX on host A connects to RX on host B and vice-versa. As the name implies, this is asynchronous and doesn’t rely on a clock signal; this means hardware support is helpful because it will handle a lot of the grunt work. A lot of common peripherals use a serial interface, but it’s important to remember that supporting multiple devices requires multiple UARTs. For example, if you want to use a serial GPS and also a serial console with a host computer, you’ll need two separate UARTs.
- Two-wire is the generic name for the I²C protocol invented by Philips. You’ll see it called TWI or I2C, too. This is also a simple communications scheme that only requires two pins (serial clock, or SCL, and serial data, or SDA), and it’s a synchronous protocol tied to a clock signal (SCL). There’s a 7-bit address space, which means you can have a lot more devices connected. Generally, you’ll have a TWI master (e.g. the microcontroller), and a number of slave peripherals; however, multiple masters are supported. The naming is unfortunate, but the documents and protocols refer to this heavily, as we’ll see. There’s a helpful TI document, Understanding the I²C Bus that describes the protocol in detail.
- The Serial Peripheral Interface (or SPI) is a lot more complicated electrically, requiring three pins plus one additional pin for each device. These pins are the serial clock (SCK), the master-out slave-in (using the same unfortunate naming as I2C) or MOSI pin, and the master-in slave-out (MISO) pin. Each peripheral also requires a slave select pin. TI also has a document covering this, Serial Peripheral Interface.
I’ll talk more about these in future articles.