0
0
Embedded Cprogramming~20 mins

I2C addressing (7-bit and 10-bit) in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
I2C Addressing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of 7-bit I2C address shifting
What is the output of this code snippet that shifts a 7-bit I2C address to form the 8-bit address for write operation?
Embedded C
uint8_t address_7bit = 0x3A; // 7-bit address
uint8_t address_8bit = address_7bit << 1; // Shift left by 1 for write
printf("0x%02X", address_8bit);
A0x75
B0x3A
C0x74
D0x1D
Attempts:
2 left
💡 Hint
Remember that the 7-bit address is shifted left by 1 bit to make room for the read/write bit.
Predict Output
intermediate
2:00remaining
10-bit I2C address first byte calculation
Given a 10-bit I2C address 0x345, what is the value of the first byte sent on the bus according to the I2C 10-bit addressing protocol?
Embedded C
uint16_t address_10bit = 0x345;
uint8_t first_byte = 0xF0 | ((address_10bit >> 7) & 0x06); // bits 9 and 8 shifted
printf("0x%02X", first_byte);
A0xF6
B0xF4
C0xF2
D0xF0
Attempts:
2 left
💡 Hint
The first byte starts with 11110 and includes bits 9 and 8 of the address in bits 2 and 1.
🔧 Debug
advanced
2:00remaining
Identify the error in 7-bit I2C address usage
What error will this code cause when used to send a 7-bit I2C address on the bus?
Embedded C
uint8_t address_7bit = 0x50;
uint8_t address_8bit = address_7bit | 0x01; // Attempt to set read bit
// Send address_8bit on bus
AThe code will cause a compile-time error due to invalid bitwise operation
BThe address is incorrect because it does not shift the 7-bit address left before adding the read bit
CThe code correctly forms the 8-bit address for read operation
DThe code will cause a runtime error due to overflow
Attempts:
2 left
💡 Hint
Think about how the 7-bit address must be shifted before adding the read/write bit.
📝 Syntax
advanced
2:00remaining
Syntax error in 10-bit I2C address byte formation
Which option contains a syntax error when trying to form the second byte of a 10-bit I2C address?
Embedded C
uint16_t addr = 0x2AA;
uint8_t second_byte = addr & 0xFF;
Auint8_t second_byte = addr & 0xFF
Buint8_t second_byte = (uint8_t)(addr & 0xFF);
Cuint8_t second_byte = addr & 0xFF;
Duint8_t second_byte = (addr & 0xFF);
Attempts:
2 left
💡 Hint
Check for missing semicolons or incorrect casting syntax.
🚀 Application
expert
2:00remaining
Calculate total bytes sent for 10-bit I2C address write
How many bytes are sent on the I2C bus when writing to a device with a 10-bit address, including address and data bytes, if the data payload is 3 bytes?
A3 bytes
B4 bytes
C6 bytes
D5 bytes
Attempts:
2 left
💡 Hint
Remember that 10-bit addressing requires two address bytes plus the data bytes.