0
0
Embedded Cprogramming~10 mins

I2C addressing (7-bit and 10-bit) 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 define a 7-bit I2C address.

Embedded C
uint8_t address = [1]; // 7-bit I2C address
Drag options to blanks, or click blank then click option'
A0x800
B0x1FF
C0x400
D0x3C
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing an address larger than 7 bits.
2fill in blank
medium

Complete the code to define a 10-bit I2C address.

Embedded C
uint16_t address = [1]; // 10-bit I2C address
Drag options to blanks, or click blank then click option'
A0x3FF
B0x7F
C0x80
D0x1000
Attempts:
3 left
💡 Hint
Common Mistakes
Using values larger than 10 bits.
3fill in blank
hard

Fix the error in the code that sets a 7-bit I2C address shifted for read/write bit.

Embedded C
uint8_t address_rw = [1] << 1; // Shift 7-bit address for R/W bit
Drag options to blanks, or click blank then click option'
A0x7F
B0x3C
C0x1E
D0x78
Attempts:
3 left
💡 Hint
Common Mistakes
Shifting an already shifted address.
4fill in blank
hard

Fill both blanks to extract the upper 2-bit and lower 8-bit parts from a 10-bit I2C address.

Embedded C
uint8_t addr_high = (address [1] 8) & 0x03; // upper 2 bits
uint8_t addr_low = address [2] 0xFF; // lower 8 bits
Drag options to blanks, or click blank then click option'
A>>
B<<
C&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using left shift instead of right shift for upper bits.
5fill in blank
hard

Fill all three blanks to create the 10-bit I2C address frame with R/W bit.

Embedded C
uint16_t frame = ((uint16_t)(0xF0 | ((address [1] 7) & 0x06)) [2] 8) | (address [3] 0xFF);
Drag options to blanks, or click blank then click option'
A>>
B<<
C|
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up shift directions or using wrong bitwise operators.