2024-11-18 04: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.
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:
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
Has anyone experienced similar issues with the INA228 using the STM32 HAL library?
Any help or suggestions would be greatly appreciated! Thanks in advance
2024-11-18 05:08 AM - edited 2024-11-18 05: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)
2024-11-18 06:39 AM - edited 2024-11-18 07: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|
+-------------+
2024-11-18 06:45 AM - edited 2024-11-18 06: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...
2024-11-18 07: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.
2024-11-18 08:12 AM - edited 2024-11-18 08: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 ?
2024-11-18 08:22 AM
Yes its my TI post!
it's a better schema i think !
2024-11-18 08: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?
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?
2024-11-18 10:23 AM
Is that before or after the isolator?
Again, does it work without the isolator?