Transferring Bits
Each piece of data you send on the I2C bus is like a puzzle piece. To make sure everyone understands the puzzle piece correctly, there is a clock signal that acts like a metronome, ticking with each piece. When the metronome is high, the puzzle piece must be stable and not change.
There are only two times when the puzzle pieces can change: when you start a conversation (START) and when you finish it (STOP).
START and STOP Conditions
Imagine you're the leader of a conversation, like the host of a meeting. You begin the discussion by saying "START" and end it by saying "STOP." While the conversation is happening (between START and STOP), no one else should interrupt or try to take control of the talk.
Sometimes, in the middle of a discussion, you might want to say something new without ending the conversation. This is like a "REPEATED START." It's like saying, "Hold on, I have more to say." But remember, even during a REPEATED START, the conversation is still ongoing until you finally say "STOP."
You can signal START and STOP by changing the level of the SDA line (the data line) when the SCL line (the clock line) is high. Think of it as a way to say "Let's start talking" or "Okay, we're done talking."
Address Packet Format
Every time you want to talk to someone on the I2C bus, you need to use a special code. It's like dialing a phone number. This code is 9 bits long: 7 bits for the address, 1 bit to say if you want to "read" or "write," and 1 bit for acknowledgment.
When you call someone (address them), they need to say "hello" back (acknowledge)
. If they're busy or can't talk, they won't say "hello." In I2C, this is done by making the SDA line low during the ninth metronome tick (ACK).
If you can't reach someone, you can end the call (STOP) or start a new one (REPEATED START). The MSB of the data byte is transmitted first.
Data Packet Format
The actual information you send is like the message you're delivering in your call. Each piece of information is 9 bits long: 8 bits for the data and 1 bit for acknowledgment.
When someone gets your message (receives data), they acknowledge it by making the SDA line low during the ninth metronome tick (ACK). If they don't acknowledge, it's like they didn't receive the message (NACK).
Combining Address and Data Packets
A complete conversation (transmission) includes START, addressing (who you're talking to), data (what you're saying), and finally, STOP (ending the talk). Just START and STOP with nothing in between doesn't make sense.
If you're sending a lot of information, you can keep talking between the address and STOP, depending on what you and the other person agreed upon in advance.
Sometimes, you can slow down or speed up the conversation using the clock signal. It's like adjusting the pace of the discussion. The person receiving the information can extend the pause between the ticks if they need more time to process.
That's the basics of how information travels on an I2C bus - like a well-organized conversation with a clear beginning, middle, and end, where everyone knows when to speak and when to listen.