0
0
Embedded Cprogramming~10 mins

Writing data to 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 device address 0x50.

Embedded C
I2C_Start();
I2C_Write([1]);
Drag options to blanks, or click blank then click option'
A0x50 << 1
B0x50
C0xA0
D0x28
Attempts:
3 left
💡 Hint
Common Mistakes
Using the device address without shifting left.
Using the read address instead of write address.
2fill in blank
medium

Complete the code to write the data byte 0x3F to the I2C device.

Embedded C
I2C_Write([1]);
Drag options to blanks, or click blank then click option'
A0x3F
B0xA1
C0x50
D0x00
Attempts:
3 left
💡 Hint
Common Mistakes
Sending the device address instead of data.
Sending a wrong data byte.
3fill in blank
hard

Fix the error in the code to properly stop the I2C transmission.

Embedded C
I2C_Stop[1];
Drag options to blanks, or click blank then click option'
A{}
B;
C[]
D()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses when calling functions.
Using incorrect punctuation after function names.
4fill in blank
hard

Fill all three blanks to write a byte 0x7A to register 0x10 of the I2C device at address 0x60.

Embedded C
I2C_Start();
I2C_Write([1]);
I2C_Write([2]);
I2C_Write([3]);
Drag options to blanks, or click blank then click option'
A0x60 << 1
B0x7A
C0x10
D0x50
Attempts:
3 left
💡 Hint
Common Mistakes
Sending data byte before register address.
Not shifting the device address left.
5fill in blank
hard

Fill all three blanks to complete the function that writes a data byte to a register of an I2C device.

Embedded C
void writeRegister(uint8_t deviceAddr, uint8_t regAddr, uint8_t data) {
    I2C_Start();
    I2C_Write([1]);
    I2C_Write([2]);
    I2C_Write([3]);
    I2C_Stop();
}
Drag options to blanks, or click blank then click option'
AdeviceAddr << 1
BregAddr
Cdata
DdeviceAddr
Attempts:
3 left
💡 Hint
Common Mistakes
Not shifting the device address.
Swapping register and data bytes.