Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU0011)

Real Time Clock modules for microcontrollers
andyjohnfisher
Posts: 3
Joined: Fri Aug 16, 2013 1:45 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by andyjohnfisher » Thu Aug 22, 2013 2:37 pm

Hello,

I am having trouble accessing the EEPROM. The following testcode code works fine for TESTLEN of up to 256 but does strange things in the first byte of each pair for TESTLEN 512 an up.
The first byte seems to get some bits stuck at '1'. This doesn't make much sense on a serial device.

I have the RTC module connected to an Arduino mini and the RTC functions work fine (although the RTC does seem to run slowly when on battery, loosing several seconds per minute!)

Help would be appreciated

Code: Select all

/* Include the wire library */
#include "Wire.h"
/* Include the Hobby Components RTC library */
#include <HCRTC.h>

/* Define the I2C addresses for the RTC and EEPROM */
#define I2CDS1307Add 0x68
#define I2C24C32Add  0x50

#define TESTLEN (256)

unsigned int index,i,j;
byte h,l;

/* Create an instance of HCRTC library */
HCRTC HCRTC;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println("");

  /************* Example write to EEPROM ***************/  

  j=0;
  for (index = 0; index < TESTLEN; index++)
  {  
    HCRTC.EEStartWrite(I2C24C32Add, index*16);
    // Sequentially write example data to the EEPROM
    for (i=0;i<8;i++) {
      h = (byte)(j>>8);
      l = (byte)(j & 0xff);
      HCRTC.EEWriteByte(h);
      HCRTC.EEWriteByte(l);
      Serial.print(h);
      Serial.print(":");
      Serial.println(l);
      j++;
    }
    // End the write sequence
    HCRTC.EEEndWrite();
    // Wait for cached data to finish writing
    delay(10);  
  }
  Serial.println("done writing");

  /************* Example read from EEPROM ***************/  

  j=0;
  for (index = 0; index < TESTLEN; index++)
  {  
    HCRTC.EEStartRead(I2C24C32Add, index*16);
    // Sequentially write example data to the EEPROM
    for (i=0;i<8;i++) {
      Serial.print(HCRTC.EEReadByte(I2C24C32Add));
      Serial.print(",");
      Serial.println(HCRTC.EEReadByte(I2C24C32Add));
      }
  }
  Serial.println("done reading!");

while(1);

}

andrew
Site Admin
Posts: 1381
Joined: Sun Aug 05, 2012 4:15 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by andrew » Thu Aug 22, 2013 5:47 pm

I can't see anything obvious wrong with your program. Could you try upping the delay time after each write cycle to see if that fixes the problem. If not, I'll set one up and take a look at the code.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

andyjohnfisher
Posts: 3
Joined: Fri Aug 16, 2013 1:45 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by andyjohnfisher » Thu Aug 22, 2013 11:19 pm

A ha!

A much simpler test that shows the problem. It seems that addresses above 4k wrap in the library somewhere!

Andy

Code: Select all

/* Include the wire library */
#include "Wire.h"
/* Include the Hobby Components RTC library */
#include <HCRTC.h>

/* Define the I2C addresses for the RTC and EEPROM */
#define I2CDS1307Add 0x68
#define I2C24C32Add  0x50

/* Create an instance of HCRTC library */
HCRTC HCRTC;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
    Serial.println("");

    HCRTC.EEStartWrite(I2C24C32Add, 0);
    HCRTC.EEWriteByte(10);
    HCRTC.EEEndWrite();
    delay(100);  
    
    HCRTC.EEStartWrite(I2C24C32Add, 4096);
    HCRTC.EEWriteByte(123);
    HCRTC.EEEndWrite();
    delay(100);  
    
    HCRTC.EEStartRead(I2C24C32Add, 0);
    Serial.print(HCRTC.EEReadByte(I2C24C32Add));
 
    while(1); 

}

andyjohnfisher
Posts: 3
Joined: Fri Aug 16, 2013 1:45 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by andyjohnfisher » Thu Aug 22, 2013 11:29 pm

OK its obvious really. The 24C32 is a 32k BIT device not a 32k BYTE device!
Sorry to waste your time.

Perhaps for those not used to these devices it would help to describe it as 32k BIT not just 32k

Thanks
Andy

andrew
Site Admin
Posts: 1381
Joined: Sun Aug 05, 2012 4:15 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by andrew » Fri Aug 23, 2013 8:31 am

Yeah, that was the fist thing I checked but forgot it is a 32K bit, not 32K device! Thanks for pointing that out, I'll update the description.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Luiz Natal (Brazil)

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by Luiz Natal (Brazil) » Sat Oct 05, 2013 10:52 pm

The module are OK, you need to use a rechargeable battery LIR2032, the voltage of this battery is 3,6v and it is reduced by diode placed between the baterry and pin 3 of DS1307, when you use a 3v battery it is reduced for 2.2 or less volts and the DS1307 dont work with this voltage (see datasheet), because there is a variant characteristcs of components in the board, some of modules may be work and others dont!

andrew
Site Admin
Posts: 1381
Joined: Sun Aug 05, 2012 4:15 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by andrew » Sun Oct 06, 2013 11:24 am

voltage of this battery is 3,6v
Correct
when you use a 3v battery
The modules are supplied with a LIR2032 3.6V lithium battery and we recommend using the same type as a replacement
it is reduced by diode placed between the battery and pin 3 of DS1307,
Although there is an on board diode, this is not between the battery and the Vbat pin.
when you use a 3v battery it is reduced for 2.2 or less volts and the DS1307 dont work with this voltage (see datasheet)
Actual battery voltage at the DS1307 Vbatt pin is around 2.6V for a good battery using the supplied LIR2032. The datasheet specifies minimum Vbat voltage of 2V and so a correctly working module should be well within this minimum spec.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

jackbell16
Posts: 2
Joined: Wed Nov 06, 2013 7:59 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by jackbell16 » Thu Nov 28, 2013 1:37 pm

Hi,
how should I connect this RTC to Arduino Uno ?

andrew
Site Admin
Posts: 1381
Joined: Sun Aug 05, 2012 4:15 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by andrew » Fri Nov 29, 2013 11:19 am

The connections to an Uno is as follows:

SCL - > A5
SDA -> A4
VCC - > +5V
GND -> GND
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

normski001
Posts: 35
Joined: Thu Dec 12, 2013 7:58 am

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by normski001 » Wed Dec 18, 2013 6:47 pm

i have wired this in to my mega 2560 gnd +5 sda to pin 0 scl to pin 21 i am using the lcd keypad shield and screen does not show time, it stays on test program hello world
i have moved the hcrtc in to library and the wire also the 1307
any ideas why please

Post Reply

Return to “RTC”