0
0
Embedded Cprogramming~10 mins

I2C acknowledge and NACK behavior in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to send an ACK after receiving a byte on I2C.

Embedded C
if (I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED)) {
    uint8_t data = I2C_ReceiveData(I2C1);
    I2C_[1](I2C1, ENABLE);  // Send ACK
}
Drag options to blanks, or click blank then click option'
ANACKConfig
BAcknowledgeConfig
CStopConfig
DStartConfig
Attempts:
3 left
💡 Hint
Common Mistakes
Using NACKConfig instead of AcknowledgeConfig
Confusing StopConfig with ACK control
2fill in blank
medium

Complete the code to send a NACK after the last byte is received on I2C.

Embedded C
if (last_byte_received) {
    I2C_[1](I2C1, ENABLE);  // Send NACK
}
Drag options to blanks, or click blank then click option'
AAcknowledgeConfig
BStopConfig
CNACKConfig
DStartConfig
Attempts:
3 left
💡 Hint
Common Mistakes
Using AcknowledgeConfig instead of NACKConfig
Forgetting to send NACK after last byte
3fill in blank
hard

Fix the error in the code to properly generate a NACK after receiving the last byte.

Embedded C
if (I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED)) {
    if (last_byte) {
        I2C_AcknowledgeConfig(I2C1, [1]);  // Should send NACK
    }
    uint8_t data = I2C_ReceiveData(I2C1);
}
Drag options to blanks, or click blank then click option'
ADISABLE
BENABLE
CTRUE
DFALSE
Attempts:
3 left
💡 Hint
Common Mistakes
Passing ENABLE instead of DISABLE
Not disabling acknowledge before last byte
4fill in blank
hard

Fill both blanks to correctly check for ACK and NACK events in I2C communication.

Embedded C
if (I2C_CheckEvent(I2C1, [1])) {
    // ACK received
}
else if (I2C_CheckEvent(I2C1, [2])) {
    // NACK received
}
Drag options to blanks, or click blank then click option'
AI2C_EVENT_MASTER_BYTE_TRANSMITTED
BI2C_EVENT_MASTER_BYTE_RECEIVED
CI2C_EVENT_MASTER_NACK
DI2C_EVENT_MASTER_MODE_SELECT
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing transmit and receive events
Using wrong event constants
5fill in blank
hard

Fill all three blanks to implement sending a NACK and STOP condition after the last byte is received.

Embedded C
if (last_byte) {
    I2C_AcknowledgeConfig(I2C1, [1]);  // Send NACK
    I2C_GenerateSTOP(I2C1, [2]);          // Generate STOP
    while (!I2C_GetFlagStatus(I2C1, [3])) {}
}
Drag options to blanks, or click blank then click option'
ADISABLE
BENABLE
CI2C_FLAG_STOPF
DI2C_FLAG_TXE
Attempts:
3 left
💡 Hint
Common Mistakes
Enabling acknowledge instead of disabling
Waiting for wrong flag
Not generating STOP condition