0
0
Embedded Cprogramming~10 mins

Why I2C is used in Embedded C - Visual Breakdown

Choose your learning style9 modes available
Concept Flow - Why I2C is used
Start
Need to connect multiple devices
Choose communication method
SPI: many wires, fast
UART: 2 wires, point-to-point
I2C: 2 wires, multi-device
I2C chosen for simplicity and multi-device support
Use I2C to communicate with sensors, memory, etc.
End
This flow shows why I2C is chosen: to connect many devices easily using only two wires.
Execution Sample
Embedded C
/* Pseudocode for I2C communication setup */
void i2c_init() {
  // Setup SDA and SCL pins
  // Configure clock speed
}

void i2c_write(unsigned char address, unsigned char data) {
  // Start condition
  // Send address + write bit
  // Send data
  // Stop condition
}
This code sets up I2C and writes data to a device at a given address.
Execution Table
StepActionDetailsResult
1Initialize I2CConfigure SDA and SCL pinsPins ready for communication
2Start ConditionMaster pulls SDA low while SCL is highDevices detect start
3Send AddressMaster sends 7-bit address + write bitTarget device recognizes address
4Send DataMaster sends data byteDevice receives data
5Stop ConditionMaster releases SDA while SCL is highCommunication ends
6EndNo more data to sendI2C bus free
💡 Communication ends after stop condition; bus is free for next use
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
SDA lineHighLow (start)Address bitsData bitsHigh (stop)High
SCL lineHighHighClock pulsesClock pulsesHighHigh
Device stateIdleDetect startAddress matchData receivedIdleIdle
Key Moments - 3 Insights
Why does I2C use only two wires for multiple devices?
I2C uses two wires (SDA for data, SCL for clock) shared by all devices, allowing many devices to connect without extra wires. See execution_table steps 2 and 3 where start and address are sent on shared lines.
What happens if the device does not recognize the address?
If no device matches the address sent in step 3, no device responds and communication stops or retries. This is why address matching is important (execution_table step 3).
Why is the stop condition important?
The stop condition (step 5) signals the end of communication and frees the bus for other devices. Without it, devices would not know when communication ends.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the state of the SDA line after step 2?
ALow
BHigh
CFloating
DPulsing
💡 Hint
Check the 'SDA line' row in variable_tracker after Step 2
At which step does the device recognize its address?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Device state' in variable_tracker and 'Send Address' in execution_table
If the stop condition is not sent, what happens to the bus?
ABus switches to SPI mode
BBus resets automatically
CBus remains busy, blocking other devices
DBus ignores data
💡 Hint
Refer to key_moments about the importance of the stop condition
Concept Snapshot
I2C uses 2 wires (SDA for data, SCL for clock) to connect multiple devices.
It allows simple multi-device communication with addressing.
Communication starts with a start condition and ends with a stop condition.
Devices listen for their address to respond.
I2C is slower but simpler and uses fewer wires than SPI.
Full Transcript
I2C is used because it allows many devices to communicate using only two wires. The master device controls the clock (SCL) and data (SDA) lines. Communication starts with a start condition where SDA goes low while SCL is high. Then the master sends the 7-bit address plus a read/write bit. Devices listen and respond if the address matches. Data bytes are sent next. Finally, the master sends a stop condition where SDA goes high while SCL is high, signaling the end of communication. This method is simple and efficient for connecting sensors, memory, and other devices on the same bus.