Serial Interfaces: UART, SPI and I2C
Design and debug the three workhorse buses at the hardware level: their electrical requirements, their timing, their topology limits, and how to prove a failing bus is failing.
Two ways in. Work the material, or if you already know this, go straight to the project and prove it.
Where this sits
- Used by tracks
- Digital PCB DesignerEmbedded Hardware Prototyper
How this skill is structured
- 1. Concepts — the ideas stated plainly, with the equations worth memorising.
- 2. Worked example — one real problem solved end to end, numbers included.
- 3. Tool demonstration — do the thing in a real open-source tool.
- 4. Resources — the specific free readings and videos, and what part of each to use.
- 5. Project — built alone, producing something a reviewer can check.
- 6. Competence checklist — what you must be able to do. This is also the audit rubric.
1. Concepts
Read these first. Tick each one when you could explain it to someone else without notes.
2. Worked example
Computing whether a UART link will work with an internal RC oscillator
ProblemAn MCU with a +/-1.5% internal oscillator must talk 115200 baud 8N1 to a USB-serial bridge with a crystal (+/-0.05%). The MCU's baud generator divides a 48 MHz clock by an integer. Will it work?
- 1Framing error budget: an 8N1 frame is 10 bit times (start, 8 data, stop). The receiver samples at the middle of each bit, so the sampling point must not drift more than half a bit by the last bit.
- 2Drift at the last bit = 9.5 bit times x (total fractional error). Setting this less than 0.5 bit gives total error < 0.5/9.5 = 5.26%.
- 3In practice receivers sample with a 16x oversampling clock and majority-vote three samples, which tightens the requirement. Use the conventional 2% total budget for a safe design, and 3% as an absolute limit.
- 4Divider error: 48,000,000 / 115200 = 416.67. The integer divider gives 417, producing an actual baud of 48e6/417 = 115,107.9. Error = (115107.9 - 115200)/115200 = -0.08%.
- 5If the part has a fractional divider, this term goes to nearly zero. Many modern parts do; check.
- 6Oscillator error: +/-1.5% over temperature and voltage, from the datasheet's guaranteed column, not the trimmed-at-25 C typical.
- 7Bridge error: +/-0.05% crystal, plus its own divider error, typically negligible.
- 8Worst case total: 1.5% + 0.08% + 0.05% = 1.63%. Under the 2% budget.
- 9But check the conditions on that 1.5%: many internal oscillators are specified at +/-1% over a narrow temperature range and +/-3% or worse over the full industrial range, or when running from a wide supply range. If your product sees -40 to +85 C, re-read the table.
- 10Suppose the full-range figure is +/-3%. Total becomes 3.13%, over budget. The link will work at room temperature and fail in the field on cold mornings — the worst possible failure mode.
- 11Options: (a) fit a crystal, (b) run at a lower baud rate (does not help — the error is fractional, not absolute), (c) use the USB or another timing reference to trim the internal oscillator at runtime, which several parts support, (d) accept a narrower operating temperature range and document it.
- 12Note that (b) is a trap that catches people: baud rate error is a percentage, so slowing down does not improve it. Only reducing the frame length would, and 8N1 is already short.
AnswerIt works if the oscillator's guaranteed accuracy over your full operating temperature and voltage range is better than about 1.9%. Check the guaranteed full-range number, not the typical room-temperature one. If it is +/-3%, fit a crystal or trim the oscillator at runtime — lowering the baud rate does not help.
3. Tool demonstration
Capture and decode all three buses, then diagnose three deliberately broken links.
4. Resources
Free and, wherever possible, openly licensed. The note tells you which part to actually use — do not read them cover to cover.
5. Project — build this on your own
About 3 hours. This is the artifact that proves the skill. Work it without a walkthrough.
Design the serial interface layer for a multi-sensor board and prove it works with captured, decoded, timing-verified evidence, including a documented diagnosis of at least two injected faults.
Deliverables
Acceptance criteria — how you know it is good enough
If you want to push further
- Add an RS-485 segment with correct termination, failsafe biasing and direction control, and capture a transaction including the turnaround.
- Write a custom sigrok decoder for one of your sensors that translates raw I2C into named register reads and writes.
6. Competence checklist
Tick these honestly. If you are auditing this skill, this is your rubric — you should be able to demonstrate every line from the project you just built.