Hello,
My project controls, through an STM32F103C8, a relay module. Attached to the board there are also an LCD module and an SHT31 sensor, both connected to the I2c (both on the first i2C. the second one isn't used). I use the Arduino IDE with the wire library and the LiquidCrystal_I2c. I have issues due to interferences from the relays module. I'm working on the hardware part but I'd like to implement some checks and recover on the software side. I've already activated the watchdog but the more frequent issue is that the LCD display is stuck while the MCU keeps working and so no reset is triggered. I have programmed the sketch so that it triggers a relay when a read from the SHT31 sensor is below a given level and so when the LCD is stuck, I'm not even sure that function is working properly. The other relay is activated on a frequency base so I know that the MCU isn't stuck. I've also implemented some checks for a soft reset of the sensor if the reads are wrong. As said, I'd like to implement some check and reset of the I2c bus or, in general, to recover the proper functioning of the LCD. Even an MCU reset would be eventually fine but I don't know how to check the LCD or i2c status.
Please note that I just started out and I have no background whatsoever so if you are so kind to reply, please keep this in mind.
recover I2c stuck
Re: recover I2c stuck
You can try to perform an end() then a begin().
Re: recover I2c stuck
Do you mean by simply looping that? I like the simplicity 
Another question, this is the code I use in setup():
Wire.begin();
sht.begin(SHT31_ADDRESS);
Wire.setClock(50000);
lcd.begin();
lcd.backlight(); // Turn on the blacklight and print a welcome message.
lcd.setCursor(4,0);
lcd.print("WELCOME1");
delay(3000);
lcd.clear();
are both wire.begin and lcd.begin necessary or can this generate conflicts and or issues?

Another question, this is the code I use in setup():
Wire.begin();
sht.begin(SHT31_ADDRESS);
Wire.setClock(50000);
lcd.begin();
lcd.backlight(); // Turn on the blacklight and print a welcome message.
lcd.setCursor(4,0);
lcd.print("WELCOME1");
delay(3000);
lcd.clear();
are both wire.begin and lcd.begin necessary or can this generate conflicts and or issues?
Re: recover I2c stuck
I tested this:
void i2cRestart(){
if((millis() - lasti2cRestart) > i2cRestartFreq){
Wire.end();
delay(500);
Wire.begin();
delay(500);
lasti2cRestart = millis();
}
}
but as soon as it triggers it resets the entire board (even with the watchdog turned OFF)
void i2cRestart(){
if((millis() - lasti2cRestart) > i2cRestartFreq){
Wire.end();
delay(500);
Wire.begin();
delay(500);
lasti2cRestart = millis();
}
}
but as soon as it triggers it resets the entire board (even with the watchdog turned OFF)
Re: recover I2c stuck
@Anz8
Please use the code formatting for your sources.
Before posting try to understand and debug your code, we could not answer to all your request each time you get stuck.
Maybe the begin/end was not the right thing or is not used correctly. Hard to tell as the library you used could not support this or it have a
side effect.
Please use the code formatting for your sources.
Before posting try to understand and debug your code, we could not answer to all your request each time you get stuck.

Maybe the begin/end was not the right thing or is not used correctly. Hard to tell as the library you used could not support this or it have a
side effect.
-
- Posts: 633
- Joined: Thu Dec 19, 2019 1:23 am
Re: recover I2c stuck
Sure: we all start somewhere.Anz8 wrote: Fri Sep 24, 2021 8:50 am ...
Please note that I just started out and I have no background whatsoever so if you are so kind to reply, please keep this in mind.
But, you have a responsibility to learn how to swim before jumping into deep water; we are not lifeguards and you will drown.
Electrical noise will ruin your day. If you have studied relays, you know they are inductors. Do you know what happens when you switch an inductor on, then off?I have issues due to interferences from the relays module. I'm working on the hardware part but I'd like to implement some checks and recover on the software side.
There are numerous procedures, but the first to try is: https://resources.altium.com/p/using-fl ... r-circuits
Continue with this read: https://forum.arduino.cc/t/can-emi-lead ... ing/648202