View previous topic :: View next topic |
Author |
Message |
otuzsubat
Joined: 24 Jun 2004 Posts: 3
|
Weekday alarm in PCF8583 |
Posted: Wed Aug 11, 2004 7:34 am |
|
|
I want to use weekday alarm in PCF8583. For example, i want that it produces an interrupt at every Monday, 13:30. My code is below. Could you say me where is the mistake?
int int2bcd(int dec){
return ((dec/10)<<4)+(dec%10);
}
void rtc_set(){
i2c_start();
i2c_write(0xA2); //send device address
i2c_write(0x00);//send address byte
i2c_write(0x80);//Stop RTC counting
/*************Write actual time ****************/
i2c_write(0x00);//Hundredth of second
i2c_write(0x00);//Seconds
i2c_write(rtc[3]);//Minutes(in BCD format)
i2c_write(rtc[2]);//Hours(in BCD format, 24hour format)
i2c_write(rtc[0]);//Year/Date(in BCD format)
i2c_write(rtc[1]);//Weekday/Month(in BCD format)
i2c_write(0x00);//Disable Timer
/*************Write alarm time ****************/
i2c_write(0xA0);// Alarm Flag, Interrupt, No timer alarm, Weekday alarm
i2c_write(0x00);//Alarm Hundredth of second
i2c_write(0x00);//Alarm Seconds
i2c_write(int2bcd(alarm.minute));//Alarm Minutes
i2c_write(int2bcd(alarm.hour));//Alarm Hours
i2c_write(0x00);//Alarm Date
i2c_write((0x01<<(alarm.day-1)));//Alarm Weekday
i2c_stop();
delay_ms(5);
i2c_start();//start transmission
i2c_write(0x00); //send device address
i2c_write(0x00);//Send address byte
i2c_write(0x04);//Start RTC counting
i2c_stop();
delay_ms(5);
} |
|
|
bdavis
Joined: 31 May 2004 Posts: 86 Location: Colorado Springs, CO
|
|
Posted: Wed Aug 11, 2004 2:01 pm |
|
|
You are writing to two different device address's - one at the top, and the one near the bottom are different. Doesn't seem correct to me... |
|
|
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
|
|
Posted: Thu Aug 12, 2004 12:29 am |
|
|
Try poking some values directly into the registers for testing.
I tried the code below and it works. For testing 15 seconds is allowed till the interrupt occurs. The interrupt flag (bit 1 in control reg.) will need to be cleared after it occurs by writing the control byte again
write_rtc(0x00,0x04);
Code: |
#define PCF8583_WRITE_ADDRESS 0xa0
void main()
{
i2c_start();
i2c_write(PCF8583_WRITE_ADDRESS);
i2c_write(0x00); // Control reg. (address 0x00), auto increment word address
i2c_write(0x80); // Stop counting
i2c_write(0x00); // Hundredths of sec.
i2c_write(0x45); // Sec.
i2c_write(0x29); // Minutes
i2c_write(0x13); // Hours
i2c_write(0x16); // Year/date Year = 0, date = 16.
i2c_write(0x28); // Weekday/month. Weekday = 1, month = 8
i2c_write(0x00); // Timer value. N/A for this case.
i2c_write(0xa0); // Alarm control. Weekday alarm, flag for interrupt
i2c_write(0x00); // Alarm hundredths
i2c_write(0x00); // Alarm secs
i2c_write(0x30); // Alarm mins
i2c_write(0x13); // Alarm hours
i2c_stop();
write_rtc(0x0e,0x02); // Alarm on weekday 1 (Monday, assuming 0 is Sunday)
write_rtc(0x00,0x04); // Control reg, enable alarm, counting
while(1); // Or get and output date/time while waiting
}
// Writes byte to PCF8583 register
void write_rtc(int8 reg,int8 data)
{
i2c_start();
i2c_write(PCF8583_WRITE_ADDRESS);
i2c_write(reg);
i2c_write(data);
i2c_stop();
}
|
|
|
|
otuzsubat
Joined: 24 Jun 2004 Posts: 3
|
|
Posted: Thu Aug 12, 2004 2:49 am |
|
|
Quote: | You are writing to two different device address's - one at the top, and the one near the bottom are different. Doesn't seem correct to me... |
I made a typing mistake. I corrected it. But still don't work. |
|
|
|