ESP-12F with DS1307

Hi All,

I’m try to read time from DS1307 using ESP-12F its giving me out put “45”

pin connect SCL = GPIO2(4) , SDA = GPIO14(5)

here is my code please advice me. :confused: :’(

#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
#define SCL 4 //--
#define SDA 5


uint8_t _second, _minute, _hour, 
_dayOfMonth,_dayOfWeek,_month,_year;

void setup() {
  Wire.begin(SCL,SDA);
  Wire.setClock(100000);
  Serial.begin(115200);
}

void loop() {
    delay(1000);
    Get_Date_Time();
}


void Get_Date_Time()
{
  ReadTime(&_second, &_minute, &_hour, &_dayOfWeek, &_dayOfMonth, &_month, &_year);
  Serial.print(_hour);
  
}

void ReadTime(byte *second,byte *minute,byte *hours,byte *DayOfWeek,byte *DayOfMonth,byte *month,byte *year)
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0); 
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
  
  *second = BCDToDEC(Wire.read() & 0x7f);
  *minute = BCDToDEC(Wire.read());
  *hours = BCDToDEC(Wire.read() & 0x3f);
  *DayOfWeek = BCDToDEC(Wire.read());
  *DayOfMonth = BCDToDEC(Wire.read());
  *month = BCDToDEC(Wire.read());
  *year = BCDToDEC(Wire.read());
  
}

//-- Convert decimal to binary code decimal
byte DECToBCD(byte value)
{
  return ( (value/10*16) + (value%10) );
}

//-- Convert binary code decimal to decimal
byte BCDToDEC(byte value)
{
  return ( (value/16*10) + (value%16) );
}

This looks odd:

pin connect SCL = GPIO2(4) , SCL = GPIO14(5)

You should have one data and one clock pin.

Further, if you are connecting the data and clock to GPIO2 and GPIO14, then you must change this:

#define SCL 4 //--
#define SDA 5

to the pins you are actually using, in this case 2 and 14.

Edit

and more . . .

The parameter order to wire.begin() should be data followed by clock:

Wire.begin(SDA, SCL)

i have change pins no result at all.then i have check voltages there was low power to DS1307 module.
then use separate power supply,ESP-12F and DS1307 module.do i need to do special configuration for I2C communication ?
please advice (IDE is arduino 1.8,time module is working fine with atmega328P ) :’(.

Try:

GPIO 4:SDA
GPIO 5:SCL

scrumfled:
Try:

GPIO 4:SDA
GPIO 5:SCL

i have tried it not working and i have tried pin configuration provided in datasheet :frowning: did not work.