Tool/software:
ello everyone,
I'm interfacing an INA228 with an STM32 microcontroller via the I2C bus. However, I'm facing a problem with the communication that I can't seem to resolve.
Setup Details:
- Microcontroller: STM32h7 (using HAL library)
- INA228 connected via I2C
- API Used: HAL_I2C_Transmit (blocking mode)
- I2C Clock Speed: Tested at both 100 kHz and 400 kHz
- Pull-up Resistors: 2.2 kΩ on SDA and SCL lines
- Configuration of GPIO in STM32h7:
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
Issue:
I'm trying to write a pointer register on the INA228 by sending a 1-byte data, in order to perform then a read on this register:
- The register address (1 byte)
I'm calling HAL_I2C_Master_Transmit(&hi2c1, INA228_ADDRESS<<1, txBuf, 1,HAL_MAX_DELAY)
txBuf contains address of register.
In most cases, the INA228 responds with a NACK. However, i tried putting my HAL_I2C_Master_Transmit in a loop and at a random iteration, device responds correctly and the transmission is successful. when its successful i tried reading register content using HAL_I2C_Master_Receive but it fails with error HAL_I2C_ERROR_AF (NACK)
- Verified the I2C address of the INA228 using HAL_I2C_IsDeviceReady --> no detection of INA228, i saw in a post that HAL_I2C_IsDeviceReady had a bug (i'm using V1.11.0), so i stopped relying on it.
- Checked the waveform with a logic analyzer; the data being sent appears to be correct.
- Reduced the I2C clock speed to 100 kHz — no improvement observed.
- Tried adding small delays between the register address byte and the data bytes — issue persists.
Has anyone experienced similar issues with the INA228 using the STM32 HAL library?
- Could this be related to timing or specific delays required by the INA228 that are not documented?
- Are there any additional I2C settings or configurations in the STM32 HAL that might help with this issue?
Any help or suggestions would be greatly appreciated! Thanks in advance