Lecture 14 - I2C

It's a trickier protocol for sure than SPI, but its very commonly used.

Overview

I2C is:

SDA is the data bus, and SCL is the clock. PU resistors (usually 10K Ω) are needed from VCC to the bus itself.

Master/Slave

You may see that one device usually is the master, and the other is the slave. But the devices don't have to be master/slave. One device may write to another, and then the opposite may happen immediately after.

Note that the logic here needs to check that SDA is pulled low and wait for the next clock. If two devices collide on trying to write to the bus (when SDA pulled low) then some systems exponentially wait (taking exponentially more time per consecutive collision) to write on the bus.

If you've heard of TWI (Two-Wire Interface), it's the same thing as I2C as this protocol is technically trademarked.

Pasted image 20240216142949.png

Notice the acknowledge bit, which the device we are sending to needs to set to low (since normally the wire is high) to say it got the data.

STM32 Registers

There's

An aside on Serial vs. Parallel Protocols

Note that usually serial protocols are faster than parallel protocols. This is because