Complete the code to define a 7-bit I2C address.
uint8_t address = [1]; // 7-bit I2C address
The 7-bit I2C address fits in 7 bits, so 0x3C is valid. Addresses like 0x1FF exceed 7 bits.
Complete the code to define a 10-bit I2C address.
uint16_t address = [1]; // 10-bit I2C address
The 10-bit I2C address can go up to 0x3FF (1023 decimal). 0x3FF fits in 10 bits.
Fix the error in the code that sets a 7-bit I2C address shifted for read/write bit.
uint8_t address_rw = [1] << 1; // Shift 7-bit address for R/W bit
The 7-bit address 0x3C must be shifted left by 1 to make room for the R/W bit. Using 0x78 is already shifted and incorrect here.
Fill both blanks to extract the upper 2-bit and lower 8-bit parts from a 10-bit I2C address.
uint8_t addr_high = (address [1] 8) & 0x03; // upper 2 bits uint8_t addr_low = address [2] 0xFF; // lower 8 bits
To get the upper bits, shift right by 8 and mask with 0x03. To get lower bits, mask with 0xFF.
Fill all three blanks to create the 10-bit I2C address frame with R/W bit.
uint16_t frame = ((uint16_t)(0xF0 | ((address [1] 7) & 0x06)) [2] 8) | (address [3] 0xFF);
Mask bits with AND, shift left to position, and combine with OR to form the frame.