Challenge - 5 Problems
I2C Addressing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
Remember that the 7-bit address is shifted left by 1 bit to make room for the read/write bit.
✗ Incorrect
The 7-bit address 0x3A (binary 0111010) shifted left by 1 becomes 0x74 (binary 1110100). This is the 8-bit address used for write operations where the least significant bit is 0.
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
The first byte starts with 11110 and includes bits 9 and 8 of the address in bits 2 and 1.
✗ Incorrect
The 10-bit address 0x345 is binary 11 0100 0101. Bits 9 and 8 are '11' which correspond to 0x06 when shifted and masked. OR with 0xF0 gives 0xF6.
🔧 Debug
advanced2: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
Attempts:
2 left
💡 Hint
Think about how the 7-bit address must be shifted before adding the read/write bit.
✗ Incorrect
The 7-bit address must be shifted left by 1 bit before setting the read bit. OR-ing directly with 0x01 does not shift the address, so the address bits are wrong on the bus.
📝 Syntax
advanced2: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;
Attempts:
2 left
💡 Hint
Check for missing semicolons or incorrect casting syntax.
✗ Incorrect
Option A is missing the semicolon at the end of the statement, causing a syntax error.
🚀 Application
expert2: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?
Attempts:
2 left
💡 Hint
Remember that 10-bit addressing requires two address bytes plus the data bytes.
✗ Incorrect
For 10-bit addressing, the master sends two address bytes (first with special bits, second with lower address bits) plus the data bytes. So 2 address bytes + 3 data bytes = 5 bytes total.