0
0
Embedded Cprogramming~10 mins

I2C acknowledge and NACK behavior in Embedded C - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - I2C acknowledge and NACK behavior
Start Condition
Send 7-bit Address + R/W bit
Wait for ACK from Receiver
Continue
Send/Receive Data
This flow shows how the I2C master sends an address and waits for an ACK from the slave. If ACK received, communication continues; if NACK, the master stops or retries.
Execution Sample
Embedded C
i2c_start();
i2c_write(address);
ack = i2c_wait_ack();
if (ack == 0) {
  i2c_write(data);
} else {
  i2c_stop();
}
This code sends a start, writes an address, waits for ACK, then writes data if ACK received; otherwise, it stops communication.
Execution Table
StepActionSignal SentACK/NACK ReceivedNext Action
1Send Start ConditionSTARTN/ASend Address
2Send Address + R/W bitAddress+R/WWaitingWait for ACK
3Wait for ACKAddress+R/WACK (0)Send Data
4Send Data ByteDataWaitingWait for ACK
5Wait for ACKDataACK (0)Continue or Stop
6Send Stop ConditionSTOPN/AEnd Communication
💡 Communication ends after sending STOP or if NACK received at any wait step.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
ackundefinedundefined0 (ACK received)undefined0 (ACK received)0
Key Moments - 2 Insights
Why does the master wait for an ACK after sending the address?
The master waits to confirm the slave received the address and is ready. If no ACK (NACK), the master knows the slave did not respond and stops communication (see execution_table step 3).
What happens if the master receives a NACK after sending data?
If the master receives a NACK after data, it means the slave cannot accept more data or an error occurred. The master should stop or retry (not shown in this trace but implied after step 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of 'ack' after step 3?
A1 (NACK received)
B0 (ACK received)
Cundefined
D-1 (error)
💡 Hint
Check the 'ACK/NACK Received' column at step 3 in execution_table.
At which step does the master send the STOP condition?
AStep 4
BStep 3
CStep 6
DStep 2
💡 Hint
Look at the 'Action' column for 'Send Stop Condition' in execution_table.
If the slave sends a NACK after the address, what should the master do next?
ASend STOP condition and end communication
BSend another address immediately
CContinue sending data
DIgnore and wait for ACK again
💡 Hint
Refer to concept_flow where NACK after address leads to STOP condition.
Concept Snapshot
I2C communication starts with a START condition.
Master sends 7-bit address + R/W bit.
Slave responds with ACK (0) or NACK (1).
ACK means continue; NACK means stop or retry.
Data bytes also require ACK from slave.
STOP condition ends communication.
Full Transcript
In I2C communication, the master begins by sending a START condition. Then it sends the 7-bit address plus a read/write bit. The slave must respond with an ACK signal (logic 0) to confirm it received the address. If the master receives an ACK, it continues by sending or receiving data bytes. Each data byte sent also requires an ACK from the slave. If the slave sends a NACK (logic 1) at any point, the master stops communication by sending a STOP condition. This process ensures both devices are synchronized and data is transferred correctly.