We are not getting proper data (Please check the attached image), we are getting only 2000/1/1 0:0:0
I followed instructions and libraries as per the below link
https://techtutorialsx.com/2016/05/22/e ... s3231-rtc/
Initially i used direct power 3.3v from usb to ds3231 module. As per suggestions i brought the new one and given the power with coin battery.
Module Link : https://potentiallabs.com/cart/buy-ds32 ... rch=ds3231
At first it was working fine then it started getting issues in eeprom then completely stopped working. Kindly requesting everyone to help me to solve the issue.
//This is the code:
#include <Wire.h>
#include <RtcDS3231.h>
const byte interruptPin = 13;
volatile bool alarm = 0;
RtcDS3231<TwoWire> rtcObject(Wire);
void setup()
{
char somedata[] = {'r','a','m','r','a','m'}; // data to write
Wire.begin(); // initialise the connection
Serial.begin(115200);
Serial.println("Writing into memory...");
rtcObject.Begin();
// write to EEPROM
i2c_eeprom_write_page(0x57, 0, (byte *)somedata, sizeof(somedata));
delay(100); //add a small delay
Serial.println(" ");
RtcDateTime currentTime=RtcDateTime(somedata[0], somedata[1], somedata[2],somedata[3],somedata[4],somedata[5]);
rtcObject.SetDateTime(currentTime);
}
void loop()
{
Serial.print("Reading memory: ");
int addr=0; //first address
// access the first address from the memory
byte b = i2c_eeprom_read_byte(0x57, 0);
while (addr <= 5)
{
Serial.print((char)b); //print content to serial port
addr++; //increase address
b = i2c_eeprom_read_byte(0x57, addr); //access an address from the memory
Serial.println(" ");
delay(1000);
}
RtcDateTime currentTime = rtcObject.GetDateTime();
char str[20];
sprintf(str, "%d/%d/%d %d:%d:%d", //%d allows to print an integer to the string
currentTime.Year(), //get year method
currentTime.Month(), //get month method
currentTime.Day(), //get day method
currentTime.Hour(), //get hour method
currentTime.Minute(), //get minute method
currentTime.Second() //get second method
);
Serial.println(str); //print the string to the serial port
delay(1000);
}
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(rdata);
Wire.endTransmission();
}
// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddresspage >> 8)); // MSB
Wire.write((int)(eeaddresspage & 0xFF)); // LSB
byte c;
for ( c = 0; c < length; c++)
Wire.write(data[c]);
Wire.endTransmission();
}
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.read();
return rdata;
}
// maybe let's not read more than 30 or 32 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,length);
int c = 0;
for ( c = 0; c < length; c++ )
if (Wire.available()) buffer[c] = Wire.read();
}
output which i am getting :
2000/1/1 0:0:0
Reading memory: ⸮
⸮
⸮
⸮
⸮
⸮
2000/1/1 0:0:0
Reading memory: ⸮
⸮
⸮
⸮
⸮
⸮
2000/1/1 0:0:0
Thanks in advance.