Chapter 7. Communicating with Peripherals

A peripheral is anything outside your processor core that the processor communicates with. Peripherals come in all shapes and sizes. Because your processor core has direct access to memory inside the processor, it barely counts as a peripheral (though memory can also be outside your chip).

So which is the best way to communicate with peripherals: UART, SPI, I2C, or something else? I get asked this question a lot. So let’s talk about why there isn’t an answer. I need a whole chapter to explain.

We’ve investigated what goes on inside your processor during the course of this book. Before you can build a system, we need to consider what goes on in other components. Communicating with the other components is a start to this. I want to show you what to look for when deciding what kind of communication method to use or writing a communications driver.

For the most part, you’ll end up using a driver from your processor’s hardware abstraction layer (HAL). You’ll need to configure it according to the external device’s datasheet and your processor’s manual. However, that breaks when you meet a new way of communicating, one without an easy driver. So let’s look at protocols and methods we’ll often use as a way of identifying the important pieces to look for in a new protocol.

Serial Communication

At its broadest definition, serial communication is the process of sending data one bit at a time over a communication pathway (usually a wire, a physical ...

Get Making Embedded Systems, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.