Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 369 of 9365. Communication Protocols and Data TransferFree lesson

Generating Precise I2C Start and Stop Conditions

Implement the specific voltage transition sequences required to signal the beginning and end of a data transaction on the bus.

Generating Precise I2C Start and Stop Conditions

In this lesson, you will learn how to manipulate the I2C bus signals to signal the beginning and end of a data transaction.

Unlike SPI, where communication is managed by dedicated chip-select lines, I2C uses the bus state itself to signal intent. Because I2C utilizes open-drain signaling with pull-up resistors, both the Serial Data (SDA) and Serial Clock (SCL) lines are held "high" by default (the idle state).

The Start Condition

A "Start" condition is a unique event that occurs while the clock line (SCL) is held high. To initiate a transaction, the master pulls the data line (SDA) from a high state to a low state. Because this transition happens while the clock is stable at logic high, it is interpreted by all slave devices as a command to start listening for an address.

The Stop Condition

A "Stop" condition signals the completion of a transaction. Here, the master allows the data line (SDA) to transition from low to high while the clock line (SCL) is held high. This specific sequence acts as the "release" signal, telling the slaves that the bus is now free for another master or a new transaction.

Implementation Logic

To implement these conditions in software, you must ensure strict adherence to the sequence of transitions:

// Generating a Start Condition
void i2c_start() {
    SDA_HIGH();    // Ensure SDA is high
    SCL_HIGH();    // Keep SCL high
    delay();       // Maintain setup time
    SDA_LOW();     // Falling edge on SDA while SCL is high
    delay();
    SCL_LOW();     // Prepare for data transfer
}

// Generating a Stop Condition
void i2c_stop() {
    SCL_LOW();
    SDA_LOW();     // Ensure SDA is low
    delay();
    SCL_HIGH();    // Raise clock first
    delay();
    SDA_HIGH();    // Rising edge on SDA while SCL is high
}

The key to these conditions is the timing. If the SDA line changes while SCL is low, it is considered a data bit change. It is only when the SDA transition occurs while SCL is high that the hardware recognizes the start or stop signaling.

Key Takeaway: I2C Start and Stop conditions are defined by unique SDA transitions that occur exclusively while the SCL clock line is held in the high state.