Problem with DS1307 Ram area

General discussion on mikroC.
Post Reply
Author
Message
DONALD3D
Posts: 62
Joined: 27 Jul 2007 19:24

Problem with DS1307 Ram area

#1 Post by DONALD3D » 14 Apr 2010 11:21

Hello,

i used a DS1307 without problem but i meet a particular problem when i want to read or write in ram area.
I would like to write a data in the first byte of the ram area (0x08h) for check if RTC is already setting at the good time by user.
If not (so if data is different) i write an init time by default.
But i have never the good data stored in Ram... or maybe the data read is bad.
I don't understand my problem.
Maybe someone have an luminous idea ? :idea:

My code is:

Code: Select all

void Test_ds1307()
{
char test, mois, an;

test = Read_RTC_RAM(ram_test);

if(test != 0x55) // test data stored in ram at ram_test (@0x08)
  {
  RTC_Initial_values();
  for (i = 0x08; i < 0x3F; i++) // on efface de 0x08 à 0x3F  zone des datas
      {
      Write_RTC_RAM(i, 0);
      Delay_ms(20);
      }
    Write_RTC_RAM(ram_test, 0x55); // if test different write 0x55 in ram_test (@0x08)
  }
}

void RTC_Initial_values() 
{
char i;

 I2C_Stop();
 delay_ms(50);

 ds1307_write(seconds_reg,0x00);   // pointe sur le registre des secondes
 while (I2C_Is_Idle() == 0) ;
 ds1307_write(minutes_reg,0x50);   // pointe sur le registre des minutes (0mn)
 while (I2C_Is_Idle() == 0) ;
 ds1307_write(hours_reg,0x23);     // pointe sur le registre des heures (16h)
 while (I2C_Is_Idle() == 0) ;
 ds1307_write(day_reg,0x00);       // pointe sur le registre des jours de la semaine(lundi, mardi, etc)
 while (I2C_Is_Idle() == 0) ;
 ds1307_write(date_reg,0x31);      // pointe sur le registre de la date du jour (n° du jour)
 while (I2C_Is_Idle() == 0) ;
 ds1307_write(month_reg,0x01);     // pointe sur le registre des mois
 while (I2C_Is_Idle() == 0) ;
 ds1307_write(year_reg,0x09);      // pointe sur le registre des années
 while (I2C_Is_Idle() == 0) ;

}

char Read_RTC_RAM(char Address)
{
unsigned char RAMValue;
unsigned char tmp;


  i2c_Start();

  while (i2c_Is_Idle() == 0) ;
  i2c_Wr(0xD0);                     // Address DS1307
  while (i2c_Is_Idle() == 0) ;
  i2c_Wr(Address);                  // Start from RAM address
  while (i2c_Is_Idle() == 0) ;
  i2c_Repeated_Start();
  while (i2c_Is_Idle() == 0) ;
  i2c_Wr(0xD1);                     // Issue a READ command

  while (i2c_Is_Idle() == 0) ;
  tmp =i2c_Rd(0);                   // Read into TEMP
  RAMValue = tmp;                   // Put it into RAMValue
  while (i2c_Is_Idle() == 0) ;
  i2c_Stop();                       // End of comm.
return RAMValue;                    // Send back readed value from RAM
}


void Write_RTC_RAM(char Address, char DataToWrite)
{
  i2c_Start();
  i2c_Wr(0xD0);                    // address DS1307
  while (i2c_Is_Idle() == 0) ;
  i2c_Wr(Address);
  while (i2c_Is_Idle() == 0) ;
  i2c_Wr(DataToWrite);
  while (i2c_Is_Idle() == 0) ;
  i2c_Stop();                      // issue stop signal
}
Thanks by advance.

DONALD3D
Posts: 62
Joined: 27 Jul 2007 19:24

Re: Problem with DS1307 Ram area

#2 Post by DONALD3D » 18 Apr 2010 10:40

Nobody for an idea at this problem ?

Post Reply

Return to “mikroC General”