cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Communication with INA228 from Texas instrument

Mnfz
Associate II

 

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:

  1. 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

 
Steps I've Taken:
  1. 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.
  2. Checked the waveform with a logic analyzer; the data being sent appears to be correct.
  3. Reduced the I2C clock speed to 100 kHz — no improvement observed.
  4. 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?

  1. Could this be related to timing or specific delays required by the INA228 that are not documented?
  2. 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

13 REPLIES 13

Please show your code, and schematic:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 


@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)

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;
}
}}

 

 
INA228 supply voltage 5V/ GND1 
                       +-------------+
(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|
+-------------+
I will see for visualisation on an oscilloscope :) Thank you! 
As for TI, i left a message on the training and forum

Please see the posting tips (which I linked) for how to properly post source code:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

and for ASCII Art:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/725146/highlight/true#M54

 

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...

 


@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.

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:

AndrewNeil_0-1731946321758.png

 

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 ?

 

 

Yes its my TI post!

it's  a better schema i think !

 

Mnfz_0-1731946842086.png

 


@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 !

Mnfz_0-1731946842086.png


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?

Mnfz
Associate II

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?

trace ina sda scl--00000.jpg

Is that before or after the isolator?

Again, does it work without the isolator?