[SOLVED] DS1307 Wrong time

Hi, all!
I connect DS1307 rtc module to arduino mega 2560. But I use CRIUS AIOP flight controller as Arduino... so it have PCA9306 onboard level converter on I2C bus... I tried to connect module before and after converter - same result...

I have tried different RTC libraries and get same result: get wrong time.

Also i have tried Arduino on Atmega328P and all works fine...

Can someone help me? )

1.png
2.png

1.png

2.png

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
  while (!Serial); // for Leonardo/Micro/Zero

  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
  }
}

void loop () {
    DateTime now = rtc.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    delay(1000);
}

You have clearly ruled out the possibility that the RTC modules is simply set with the wrong time ?
Have you removed the battery, waited and put it back to see if you get different results ?

6v6gt:
You have clearly ruled out the possibility that the RTC modules is simply set with the wrong time ?
Have you removed the battery, waited and put it back to see if you get different results ?

6v6gt, in the code time outputs to serial each second… but look at seconds… 0 1 0 1 4 5 4 5 …

Yeah, i have tried to remove battery… same result.

On Arduino UNO all works fine… this is strange )

OK. You get good results with the DS1307 connected to a Uno, but not when connected to the CRIUS AIOP.

Maybe it is an I2C bus address conflict. DS1307 has an I2C address of 0x68. You could test this by removing the DS1307 from the CRIUS AIOP and running an I2C scanner on it to see if something else is still using this address.

6v6gt:
OK. You get good results with the DS1307 connected to a Uno, but not when connected to the CRIUS AIOP.

Maybe it is an I2C bus address conflict. DS1307 has an I2C address of 0x68. You could test this by removing the DS1307 from the CRIUS AIOP and running an I2C scanner on it to see if something else is still using this address.

I just desoldered PCA9306 level converter from CRIUS board(it means that i have disconnected all other devices from I2C bus) and now DS1307 works well...

So... if there is an address conflict how can i resolve it?

I will try to solder level converter back and try to run I2C scanner.

3.png

3.png

I have disconnected DS1307 from board and start I2C scanner...
Yep there is something that have 0x68 address...

Thanks a lot, 6v6gt :slight_smile:

P.S. This is MPU6050 (gyro+accel) - 0x68 address.

4.png

4.png

I have changed MPU6050 address to 0x69 by pulling up AD0 pin on MPU6050. Now all devices works on I2C bus.

5.png

5.png

Glad to hear it - you can edit the subject line with '(solved)' added if you like :slight_smile: