Closed 73-de-LZ closed 1 year ago
Found a solution. The reason was known behavior of Wire library, as mentioned here: [https://www.arduino.cc/reference/en/language/functions/communication/wire/]
Recent versions of the Wire library can use timeouts to prevent a lockup in the face of certain problems on the bus, but this is not enabled by default (yet) in current versions. It is recommended to always enable these timeouts when using the Wire library. See the Wire.setWireTimeout function for more details.
Fortunately the new version of the library support timeout:
Modified 2020 by Greyson Christoforo (grey@hismailbox) to implement timeouts
// twi_timeout_us > 0 prevents the code from getting stuck in various while loops here // if twi_timeout_us == 0 then timeout checking is disabled (the previous Wire lib behavior) // at some point in the future, the default twi_timeout_us value could become 25000 // and twi_do_reset_on_timeout could become true // to conform to the SMBus standard // http://smbus.org/specs/SMBus_3_1_20180319.pdf
So the easy way is to add in the begining of the sketch:
`#include <Wire.h>`
and in the setup to define a timeout just before initializing:
void setup() { Wire.setWireTimeout(25000); // timeout for bus operations // initializing the rtc if(!rtc.begin()) { Serial.println("Couldn't find RTC!"); Serial.flush(); while (1) delay(10); }
Now the example working as expected.
According to your example if there is no DS3231 connected it should print it, but this does not happen and code is blocked:
Just try without any RTC connected this:
Serial.println(rtc.begin());
it will return 1 only when you connect DS3231, using Arduino NANO.