2025-07-10 8:23 AM
I am attempting to transmit four bytes via I2C to a device with address 0x27, using the code below.
data_t[0] = 0x01;
data_t[1] = 0x02;
data_t[2] = 0x04;
data_t[3] = 0x08;
HAL_I2C_Master_Transmit (&hi2c4, 0x27U,(uint8_t *) data_t, 4, 100);
My understanding is that the structure of an I2C message is
7 bit addr | R/W bit = 0 (for write) | Data
The address is 0x27 = 0b0100111
The RW bit is 0 for W
So the header byte is then 0b01001110 = 0x4E
So I would expect one of two possible things to happen when I use this command. Either
[0x4E],[0x01],[0x4E],[0x02],[0x4E],[0x04],[0x4E],[0x08]
[0x4E],[0x01],[0x02],[0x04],[0x08]
What I actually see on the logic analyser below. So there is 5 bytes, which is something I would have expected, but it seems to be just repeating the address each time, and never actually writing the data.
If anyone could offer any insight on what is going wrong here, it would be appreciated.
2025-07-10 9:00 AM
Simply HAL use shifted addr:
HAL_I2C_Master_Transmit (&hi2c4, 0x27U<<1,(uint8_t *) data_t, 4, 100);