Wire does not always connect to I2C properly

Working libraries, libraries being ported and related hardware
Post Reply
kvv213
Posts: 38
Joined: Thu Dec 26, 2019 10:58 pm

Wire does not always connect to I2C properly

Post by kvv213 »

Hello All!

I've faced a strange problem that I don't understand how to solve properly.

I have stm32f103 chip that is connected with en EEPROM via I2C. I use STM32Duino core and work with EEPROM via Wire lib. In the most cases everything works well and I connect to I2C EEPROM and can read and can write.

But sometimes, at very rare cases, I can't connect to I2C properly. In the meaning that I connect to it with the same mannor and it seems to be connected. But when I read it returns something random and when I try to write it doesn't. At the same time no errors is returned at all. So from Wire it looks like everything is fine.

So, what shall I do in that way? How to determine that I2C is connected properly? And how to reconnect if I see that there is a problem?

PS. The first thing that comes in my mind - try to write something and read it back. If the value is correct then continue to work otherwise - reboot. But it doesn't seems to be a good solution.

PSS. The code for init:
Wire.setSCL(I2C_SCL);
Wire.setSDA(I2C_SDA);
Wire.begin();

PSS. EEPROM that I use is AT24C08
User avatar
fpiSTM
Posts: 1757
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Wire does not always connect to I2C properly

Post by fpiSTM »

The next release will include several bugfixes for I2C maybe this will solve your issue
hennysmath
Posts: 2
Joined: Thu Mar 09, 2023 9:36 am

Re: Wire does not always connect to I2C properly

Post by hennysmath »

One approach to detecting and resolving this issue is to use a handshake protocol between the STM32 and the EEPROM. For example, you could send a specific byte sequence to the EEPROM and expect a specific response ovo game If the response is not what you expect, then you can assume that the connection is not working properly and take appropriate action (such as resetting the I2C bus or resetting the STM32).
Post Reply

Return to “Libraries & Hardware”