problem with pcf8583

my output is

This time is
0 0 0

and this is my code

#include <Wire.h>
#include <string.h>
#include <stdio.h>
unsigned int RTC_ADDR=B10100000;
typedef struct clock
{
char sec;
char minute;
char hour;
}clock;
clock rtc;

void setup ()
{
beginSerial(9600);
Wire.begin();
}
void rtc_write(unsigned char addr,unsigned char reg_addr,char data)
{
Wire.beginTransmission(addr);
Wire.send(reg_addr);
Wire.send(data);
Wire.endTransmission();
}

void rtc_write_data()
{
rtc_write(RTC_ADDR,B00000010,rtc.sec);
rtc_write(RTC_ADDR,B00000011,rtc.minute);
rtc_write(RTC_ADDR,B00000100,rtc.hour);
}

void loop()
{
Wire.requestFrom(RTC_ADDR,3);
rtc.sec=Wire.receive();
rtc.minute=Wire.receive();
rtc.hour=Wire.receive();
Serial.println(“This time is”);
Serial.print("\t");
Serial.print(rtc.sec,DEC);
Serial.print("\t");
Serial.print(rtc.minute,DEC);
Serial.print("\t");
Serial.print(rtc.hour,DEC);
Serial.println();
delay(1000);
}

:’( :’( :’(
What i do wrong ???

unsigned int RTC_ADDR=B10100000;

First problem is the I2C address you are using. The wire library routine just need the high 7 bits of the address as bit 0 is a read/write bit that it appends as needed. So change it to RTC_ADDR=0x50;

Lefty

My new code is

#include <Wire.h>
#include <string.h>
#include <stdio.h>
unsigned int RTC_ADDR=B01010000;
typedef struct clock
{
char sec;
char minute;
char hour;
}clock;
clock rtc;

void setup ()
{
beginSerial(9600);
Wire.begin();
}
void rtc_write(unsigned char addr,unsigned char reg_addr,unsigned char data)
{
Wire.beginTransmission(addr);
Wire.send(reg_addr);
Wire.send(data);
Wire.endTransmission();
}

void rtc_write_data()
{
rtc_write(RTC_ADDR,B00000010,rtc.sec);
rtc_write(RTC_ADDR,B00000011,rtc.minute);
rtc_write(RTC_ADDR,B00000100,rtc.hour);
}

void rtc_read(unsigned char addr,unsigned char reg_addr,char* data)
{
Wire.beginTransmission(addr);
Wire.send(reg_addr);
Wire.endTransmission();

Wire.beginTransmission(addr);
Wire.send(B01010001);
*data= Wire.receive();
Wire.endTransmission();
}

void rtc_read_data()
{
rtc_read(RTC_ADDR,B00000010,&rtc.sec);
rtc_read(RTC_ADDR,B00000011,&rtc.minute);
rtc_read(RTC_ADDR,B00000100,&rtc.hour);
}

void setTime()
{
rtc.sec=B00000000; //00
rtc.minute=B00010101; //15
rtc.hour=B00010111; //17
rtc_write_data();
}

void loop()
{
rtc_read_data();
Serial.print(“This time is”);
Serial.print("\t");
Serial.print(rtc.sec,DEC);
Serial.print("\t");
Serial.print(rtc.minute,DEC);
Serial.print("\t");
Serial.println(rtc.hour,DEC);
delay(1000);
}

the result is

“This time is 0 0 0”

??? :-? :-? :-? :-? :-? :-/ :-/ :-/ :-/ :-/

I'm not too good at reading others code yet as I'm still pretty new with C. But back to the I2C address. Looking at a data sheet the PCF8583 can be wired to use address 0X50 or 0x51 depending on the state of input pin 3 of the chip. If the pin 3 is wired high then 0x51 is the right addresss to use, if it's wired to ground then 0x50 should be used. This feature is so that one could run two clock modules on the same I2C buss if they wished to.

So check your RTC module or wiring to see what pin 3 is set to and correct the address if required.

Lefty