0
0
Embedded Cprogramming~10 mins

I2C bus architecture (SDA, SCL) in Embedded C - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - I2C bus architecture (SDA, SCL)
Start Condition
Master sends clock on SCL
Master sends data bit on SDA
Slave reads data bit on SDA
Master waits for ACK from Slave
Repeat for all bits
Stop Condition
The I2C bus uses two lines: SDA for data and SCL for clock. The master controls the clock and data bits, and the slave responds with acknowledgments.
Execution Sample
Embedded C
void i2c_write_bit(int bit) {
  set_SDA(bit);       // Set data line
  set_SCL(1);        // Clock high
  delay();           // Wait
  set_SCL(0);        // Clock low
}
This code sends one bit on the I2C bus by setting SDA and toggling SCL.
Execution Table
StepSCL (Clock)SDA (Data)ActionResult
10Start (High)Start Condition: SDA goes low while SCL is highBus ready for data
20->11Set SDA to 1, then SCL highData bit 1 sent
31->01SCL goes lowPrepare for next bit
40->10Set SDA to 0, then SCL highData bit 0 sent
51->00SCL goes lowPrepare for next bit
60->1ACK (Slave pulls SDA low)Slave acknowledgesMaster receives ACK
71->0ACKSCL goes lowReady for next byte or stop
81Stop (Low->High)Stop Condition: SDA goes high while SCL is highBus released
💡 Stop condition ends communication, SDA and SCL return to idle high state
Variable Tracker
Signal LineStartAfter Step 2After Step 4After Step 6After Step 8
SCL1 (idle)1111 (idle)
SDA1 (idle)100 (ACK low)1 (idle)
Key Moments - 2 Insights
Why does SDA change only when SCL is low except for start and stop?
Because data bits on SDA must be stable when SCL is high to be read correctly. This is shown in steps 2 and 4 where SDA changes before SCL goes high.
What is the purpose of the ACK bit from the slave?
The ACK bit (step 6) lets the master know the slave received the data. The slave pulls SDA low during SCL high to acknowledge.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of SDA during step 4?
AHigh (1)
BLow (0)
CFloating
DToggling
💡 Hint
Check the SDA column in row for step 4 in the execution_table
At which step does the slave send an acknowledgment?
AStep 2
BStep 4
CStep 6
DStep 8
💡 Hint
Look for the ACK action in the execution_table rows
If SDA changed while SCL was high during data bits, what would happen?
AData would be read incorrectly
BCommunication would speed up
CSlave would send NACK
DNothing changes
💡 Hint
Refer to key_moments about SDA stability during SCL high
Concept Snapshot
I2C uses two lines: SDA (data) and SCL (clock).
Master controls SCL and sets SDA bits.
Data bits must be stable when SCL is high.
Start: SDA falls while SCL high.
Stop: SDA rises while SCL high.
Slave ACKs by pulling SDA low during SCL high.
Full Transcript
The I2C bus architecture uses two wires: SDA for data and SCL for clock. Communication starts with a start condition where SDA goes low while SCL is high. The master sends data bits by setting SDA and toggling SCL. Data bits must be stable when SCL is high so the slave can read them correctly. After each byte, the slave sends an acknowledgment by pulling SDA low during the clock pulse. Communication ends with a stop condition where SDA goes high while SCL is high. This ensures clear signaling and synchronization between master and slave devices on the bus.