0
0
Embedded Cprogramming~10 mins

Reading data from I2C device 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 start an I2C transmission to the device address.

Embedded C
HAL_I2C_Master_Transmit(&hi2c1, [1], data, size, timeout);
Drag options to blanks, or click blank then click option'
A0xFF
B0x50
C0x00
D0xA0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the 7-bit address without shifting.
Using the read address instead of write address.
2fill in blank
medium

Complete the code to read data from the I2C device.

Embedded C
HAL_I2C_Master_Receive(&hi2c1, [1], buffer, length, timeout);
Drag options to blanks, or click blank then click option'
A0xA1
B0x50
C0xA0
D0x00
Attempts:
3 left
💡 Hint
Common Mistakes
Using the write address instead of the read address.
Not shifting the address before use.
3fill in blank
hard

Fix the error in the code to correctly read a register from the I2C device.

Embedded C
uint8_t reg = 0x10;
HAL_I2C_Master_Transmit(&hi2c1, [1], &reg, 1, timeout);
HAL_I2C_Master_Receive(&hi2c1, 0xA1, &data, 1, timeout);
Drag options to blanks, or click blank then click option'
A0x10
B0xA1
C0xA0
D0x50
Attempts:
3 left
💡 Hint
Common Mistakes
Using the read address in the transmit function.
Mixing up device addresses.
4fill in blank
hard

Fill both blanks to read multiple bytes from a register.

Embedded C
uint8_t reg = [1];
HAL_I2C_Master_Transmit(&hi2c2, [2], &reg, 1, 100);
Drag options to blanks, or click blank then click option'
A0x20
B0xB0
C0xB1
D0x30
Attempts:
3 left
💡 Hint
Common Mistakes
Using the read address in the transmit function.
Using wrong register address.
5fill in blank
hard

Fill all three blanks to complete the I2C read sequence for a sensor register.

Embedded C
uint8_t reg = [1];
HAL_I2C_Master_Transmit(&hi2c3, [2], &reg, 1, 100);
HAL_I2C_Master_Receive(&hi2c3, [3], &value, 1, 100);
Drag options to blanks, or click blank then click option'
A0x15
B0xC0
C0xC1
D0x16
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up read and write addresses.
Using incorrect register address.