0
0
Embedded Cprogramming~10 mins

Start and stop conditions 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 generate a start condition on the I2C bus.

Embedded C
I2C->CR1 |= [1];  // Generate start condition
Drag options to blanks, or click blank then click option'
AI2C_CR1_START
BI2C_CR1_ACK
CI2C_CR1_STOP
DI2C_CR1_PE
Attempts:
3 left
💡 Hint
Common Mistakes
Using the stop condition bit instead of the start condition bit.
Confusing the peripheral enable bit with the start condition bit.
2fill in blank
medium

Complete the code to generate a stop condition on the I2C bus.

Embedded C
I2C->CR1 |= [1];  // Generate stop condition
Drag options to blanks, or click blank then click option'
AI2C_CR1_STOP
BI2C_CR1_ACK
CI2C_CR1_PE
DI2C_CR1_START
Attempts:
3 left
💡 Hint
Common Mistakes
Using the start condition bit instead of the stop condition bit.
Confusing the acknowledge bit with the stop condition bit.
3fill in blank
hard

Fix the error in the code to correctly generate a start condition and wait for it to be set.

Embedded C
I2C->CR1 |= [1];
while(!(I2C->SR1 & I2C_SR1_SB));  // Wait for start bit set
Drag options to blanks, or click blank then click option'
AI2C_CR1_PE
BI2C_CR1_STOP
CI2C_CR1_ACK
DI2C_CR1_START
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the stop bit instead of the start bit.
Not waiting for the start bit flag in the status register.
4fill in blank
hard

Fill both blanks to generate a stop condition and wait until the bus is free.

Embedded C
I2C->CR1 |= [1];
while(I2C->SR2 & [2]);  // Wait until bus busy flag clears
Drag options to blanks, or click blank then click option'
AI2C_CR1_STOP
BI2C_SR2_BUSY
CI2C_CR1_START
DI2C_SR1_SB
Attempts:
3 left
💡 Hint
Common Mistakes
Waiting on the wrong status register flag.
Setting the start bit instead of the stop bit.
5fill in blank
hard

Fill all three blanks to generate a start condition, wait for it, and then generate a stop condition.

Embedded C
I2C->CR1 |= [1];  // Start condition
while(!(I2C->SR1 & [2]));  // Wait for start bit
I2C->CR1 |= [3];  // Stop condition
Drag options to blanks, or click blank then click option'
AI2C_CR1_START
BI2C_SR1_SB
CI2C_CR1_STOP
DI2C_CR1_ACK
Attempts:
3 left
💡 Hint
Common Mistakes
Not waiting for the start bit flag before generating the stop condition.
Using the acknowledge bit instead of start or stop bits.