Simvik

I2C address byte

Build the first byte of an I2C transfer. An easy embedded C problem (Protocols, framing and checksums), run and graded in the browser.

easy · Protocols, framing and checksums · i2c

An I2C transfer starts with one byte: the 7-bit device address in bits 7..1 and the direction in bit 0, where 1 means read and 0 means write.

Return that byte for the 7-bit address addr7.

Starter code

uint8_t i2c_address_byte(uint8_t addr7, bool read) {
  // aaaaaaa r
  return addr7;
}

Example tests

Write to an EEPROM at 0x50

printf("0x%02X\n", i2c_address_byte(0x50, false));

Expected output:

0xA0

Read from it

printf("0x%02X\n", i2c_address_byte(0x50, true));

Expected output:

0xA1

Learn it first

More Protocols, framing and checksums problems