I2C Communication with INA228 from Texas instrument
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-18 4:46 AM
Hello 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
- 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
- Labels:
-
STM32H7 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-18 5:08 AM - edited ‎2024-11-18 5:09 AM
Please show your code, and schematic:
@Mnfz wrote:1. Checked the waveform with a logic analyzer; the data being sent appears to be correct.
That's good - but have you also checked with an oscilloscope?
An oscilloscope would show if there are any "analogue" issues on your I2C lines - eg, pullups too high or too low ...
A good diagram here showing the (analogue) effect of too-high and too-low pullup values:
https://electronics.stackexchange.com/a/473799
Have you contacted TI about this? They should be able to comment whether your LA traces look appropriate for their device...
https://www.ti.com/product/INA228#support-training
(When cross-posting to multiple forums, always give links between threads - so everyone can see the whole story)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-18 6:39 AM - edited ‎2024-11-18 7:48 AM
Hey Andrew, thanks for your reply, concerning my code:
// INA228_ADDRESS = 0x44
uint8_t txBuf[1] = {0};
for (;;;) {
// Writing register pointer for configuration register to INA228 in blocking mode, in order to read back the content
HAL_StatusTypeDef state = HAL_I2C_Master_Transmit(&hi2c1, INA228_ADDRESS<<1, txBuf, 1, HAL_MAX_DELAY);
if (state == HAL_OK) {
// Can be reached randomly
uint8_t rxBurf[2] = {0};
// This call should return rxBuf field with pointed register content (16bits)
state = HAL_I2C_Master_Receive(&hi2c1, INA228_ADDRESS << 1, rxBuf, 2, HAL_MAX_DELAY);
if (state == HAL_OK){
// Never reached
int32_t conf = rxBuf[0] << 8 | rxBuf[1];
INFO("conf_reg: %ld", conf);
return;
} else {
ERROR("Receiving register conf content failed with error: %d, flagError: %ld",state, hi2c1.ErrorCode);
return;
}
}}
+-------------+
(C = 100nV)5v|VDD1 VDD2|3v3 (C = 100nV)
+ +
INA228-SDA<---2.2KO--->+ ADUM1250SRZ +<---2.2KO---> I2C-SDA-stm32
INA228-SCL<---2.2KO----+ +<---2.2KO---I2C-SCL-stm32
|GND1 GND2|
+-------------+
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-18 6:45 AM - edited ‎2024-11-18 6:58 AM
Please see the posting tips (which I linked) for how to properly post source code:
and for ASCII Art:
Also what boards are you using - manufacturer boards? 3rd-party? custom?
@Mnfz wrote:an overview of my connections
You didn't previously mention an isolator. Part number?
Does it work without the isolator?
@Mnfz wrote:As for TI, i left a message on the training and forum
Please give a link.
Also give a link over there back to here.
Again, so that everyone (both there and here) can see the entire story - eg, they will also want to know about the isolator...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-18 7:57 AM
@Andrew Neil wrote:Have you contacted TI about this? They should be able to comment whether your LA traces look appropriate for their device...
Also post the LA trace here.
And the scope trace.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-18 8:12 AM - edited ‎2024-11-18 8:13 AM
Thanks for fixing the formatting.
But this looks strange:
@Mnfz wrote:+-------------+
(C = 100nV)5v|VDD1 VDD2|3v3 (C = 100nV)
+ +
INA228-SDA<---2.2KO--->+ ADUM1250SRZ +<---2.2KO---> I2C-SDA-stm32
INA228-SCL<---2.2KO----+ +<---2.2KO---I2C-SCL-stm32
|GND1 GND2|
+-------------+
Are you saying you have the 2k2 resistors in series between the devices?
Pull-ups should go like this:
I guess this is your TI post: https://e2e.ti.com/support/amplifiers-group/amplifiers/f/amplifiers-forum/1439796/ina228-failed-to-communicate-with-ina228/5520867 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-18 8:22 AM
Yes its my TI post!
it's a better schema i think !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-18 8:27 AM
@Mnfz wrote:Yes its my TI post!
Great - don't forget to give a link there back to here!
They will also want to see your schematic, and have already asked for the oscilloscope trace.
@Mnfz wrote:it's a better schema i think !
Better - we can see that the pullups are properly pullups - but too low resolution to read any of the text.
Again, have you tried this without the isolator?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-18 10:06 AM
This is a visualize simultaneously signals on clock and data lines , I notice a desynchronization between the data
and the clock, it seems as if its the source of my problem, data frames are not cached due to this is that correct ?
As for signals shapes, i think there is no problem related to Pullups, what do you think?
 
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-18 10:23 AM
Is that before or after the isolator?
Again, does it work without the isolator?
