CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RTC problem with x1226

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
simon630



Joined: 07 Sep 2003
Posts: 17

View user's profile Send private message

RTC problem with x1226
PostPosted: Wed Jan 22, 2003 8:07 pm     Reply with quote

dear friends,
i am now having some problems with the rtc module x1226. i wrote the data to the rtc last night. and this morning when i came back, i found that the HR did not trigger. the correct time should be 08:52:00. however, what i read from the RTC was 32:52:00. could anybody help? thx.
following is my routines for rtc:
#define CLKBASE 0x30 //Clock base address
#define _SEC 0x30 //Sec
#define _MIN 0x31 //Min
#define _HR 0x32 //Hour
#define _DAY 0x33 //Date
#define _MTH 0x34 //Month
#define _YR 0x35 //Year
#define _DOW 0x36 //Day of week
#define _Y2K 0x37 //19 or 20
#define _SR 0x3F //Status

//------------------------------------------------------------------------------------------
char read_rtc(int addr) { //Read 1 byte (see Fig.11 x1226 datasheet)

char data;

i2c_start();
i2c_write(0xDE);
i2c_write(0); //16-bit addr is 00000xxx xxxxxxxx
i2c_write(addr); //For CCR only, 8-bit addr is used
i2c_start();
i2c_write(0xDF);
data=i2c_read(0); //0:No Ack, 1:Ack
i2c_stop();
return(data);
}

//------------------------------------------------------------------------------------------
void wr_rtc(int addr, char data) //Write 1 byte to non EE (no delay)
{
i2c_start();
i2c_write(0xDE);
i2c_write(0);
i2c_write(addr);
i2c_write(data);
i2c_stop();
}
void write_rtc(int addr, char data)
{
wr_rtc(_SR,02); //Set WEL (Write Enable Latch)
wr_rtc(_SR,06); //Set both RWEL (Reg WEL) & WEL
wr_rtc(addr,data); //Write byte to rtc
wr_rtc(_SR,0); //Disable write
}

main(){
...
write_rtc(_DAY, buf[8]); //Update rtc
write_rtc(_MTH, buf[9]);
write_rtc(_YR, buf[10]);
write_rtc(_HR, buf[11]);
write_rtc(_MIN, buf[12]);
write_rtc(_SEC, 0x01);
write_rtc(_DOW, buf[13]);
write_rtc(_Y2K, 0x20);

while(1){
hr=read_rtc(_HR);
min=read_rtc(_MIN);

...
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10915
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: RTC problem with x1226
PostPosted: Thu Jan 23, 2003 3:31 pm     Reply with quote

:=dear friends,
:= i am now having some problems with the rtc module x1226. i wrote the data to the rtc last night. and this morning when i came back, i found that the HR did not trigger. the correct time should be 08:52:00. however, what i read from the RTC was 32:52:00. could anybody help? thx.
-------------------------------------------------------
Your code looks basically good. You followed the timing
diagram in the data sheet very closely.

I wonder if there is a bug in the chip. What if you really
need a delay after all writes to the chip ? Maybe you should
try that, as a test. Example:

void wr_rtc(int addr, char data)
{
i2c_start();
i2c_write(0xDE);
i2c_write(0);
i2c_write(addr);
i2c_write(data);
i2c_stop();
delay_ms(10); // Add this delay statement
}


If the change above doesn't completely solve the problem,
then check these other issues:
1. Make sure the "Block Protect" bits are not set.
This would disable writing to the CCR registers.

2. Are you using battery backup ? If not, the data sheet
says you must connect that pin to ground.

3. Did you check if the time is ever incrementing ?
You said you checked it the next day and it was wrong,
but did you check it 5 minutes after start-up, to see
if it was even working at all ?

4. On page 3 of the data sheet, in "Real Time Clock Operation",
it says that when it powers-up after the loss of Vcc and
Vback, the clock will not operate until you write at least
one byte to the clock register. Could this be what's
happening ? There is a bit for "total power failure" that
you can check.

5. The value that you're reading for hours, "32", also
happens to be the hex address of the Hours register.
Is it possible that you've got a mixup in your printf()
statement, and are displaying the wrong variable ?
(Just trying to suggest any possible sources of errors).

6. The data sheet is marked "Preliminary". There could be
bugs. Maybe ask Xicor tech support for a sample driver
and schematic. Even if you have to translate it from
8051 assembly, it would be worth having.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10949
simon630



Joined: 07 Sep 2003
Posts: 17

View user's profile Send private message

Re: RTC problem with x1226
PostPosted: Fri Jan 24, 2003 8:05 pm     Reply with quote

:=:=dear friends,
:=:= i am now having some problems with the rtc module x1226. i wrote the data to the rtc last night. and this morning when i came back, i found that the HR did not trigger. the correct time should be 08:52:00. however, what i read from the RTC was 32:52:00. could anybody help? thx.
:=-------------------------------------------------------
:=Your code looks basically good. You followed the timing
:=diagram in the data sheet very closely.
:=
:=I wonder if there is a bug in the chip. What if you really
:=need a delay after all writes to the chip ? Maybe you should
:=try that, as a test. Example:
:=
:=void wr_rtc(int addr, char data)
:={
:=i2c_start();
:=i2c_write(0xDE);
:=i2c_write(0);
:=i2c_write(addr);
:=i2c_write(data);
:=i2c_stop();
:=delay_ms(10); // Add this delay statement
:=}
:=
:=
:=If the change above doesn't completely solve the problem,
:=then check these other issues:
:=1. Make sure the "Block Protect" bits are not set.
:= This would disable writing to the CCR registers.
:=
:=2. Are you using battery backup ? If not, the data sheet
:= says you must connect that pin to ground.
:=
:=3. Did you check if the time is ever incrementing ?
:= You said you checked it the next day and it was wrong,
:= but did you check it 5 minutes after start-up, to see
:= if it was even working at all ?
:=
:=4. On page 3 of the data sheet, in "Real Time Clock Operation",
:= it says that when it powers-up after the loss of Vcc and
:= Vback, the clock will not operate until you write at least
:= one byte to the clock register. Could this be what's
:= happening ? There is a bit for "total power failure" that
:= you can check.
:=
:=5. The value that you're reading for hours, "32", also
:= happens to be the hex address of the Hours register.
:= Is it possible that you've got a mixup in your printf()
:= statement, and are displaying the wrong variable ?
:= (Just trying to suggest any possible sources of errors).
:=
:=6. The data sheet is marked "Preliminary". There could be
:= bugs. Maybe ask Xicor tech support for a sample driver
:= and schematic. Even if you have to translate it from
:= 8051 assembly, it would be worth having.

thank you for ur suggestion.
1. :=delay_ms(10); // Add this delay statement
because this development is a time critical application, i dont think i can afford 10ms delay during communication. if really need to put in the dalay, i would rather change another rtc module.
2. i think the battery backup pin may be a cause for this problem. i left it float instead of tying to ground. now doing testing. do not know exactly happens if floating that pin.
3. the rtc incremented after i initialised. only that it could not trigger from 24 to 0. (although "32", also
happens to be the hex address of the Hours register. ??) would u elaborate on this, i didn't quite get it.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10985
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: RTC problem with x1226
PostPosted: Fri Jan 24, 2003 11:16 pm     Reply with quote

:=1. :=delay_ms(10); // Add this delay statement
:=because this development is a time critical application, i dont think i can afford 10ms delay during communication. if really need to put in the dalay, i would rather change another rtc module.
:=2. i think the battery backup pin may be a cause for this problem. i left it float instead of tying to ground. now doing testing. do not know exactly happens if floating that pin.
:=3. the rtc incremented after i initialised. only that it could not trigger from 24 to 0. (although "32", also
:=happens to be the hex address of the Hours register. ??) would u elaborate on this, i didn't quite get it.

------------------

Hopefully it will be the battery backup pin.

With respect to the "32", I just meant that, possibly, in
your diagnostic printf statements, that number might have
gotten juxtaposed accidently and misinterpreted as the Hours.
That comment was just a shot in the dark.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10987
simon630



Joined: 07 Sep 2003
Posts: 17

View user's profile Send private message

Re: RTC problem with x1226
PostPosted: Mon Jan 27, 2003 6:02 am     Reply with quote

:=:=1. :=delay_ms(10); // Add this delay statement
:=:=because this development is a time critical application, i dont think i can afford 10ms delay during communication. if really need to put in the dalay, i would rather change another rtc module.
:=:=2. i think the battery backup pin may be a cause for this problem. i left it float instead of tying to ground. now doing testing. do not know exactly happens if floating that pin.
:=:=3. the rtc incremented after i initialised. only that it could not trigger from 24 to 0. (although "32", also
:=:=happens to be the hex address of the Hours register. ??) would u elaborate on this, i didn't quite get it.
:=
:=------------------
:=
:=Hopefully it will be the battery backup pin.
:=
:=With respect to the "32", I just meant that, possibly, in
:=your diagnostic printf statements, that number might have
:=gotten juxtaposed accidently and misinterpreted as the Hours.
:=That comment was just a shot in the dark.

still can not work even i connect battery backup pin to either ground or a backup source. why?
___________________________
This message was ported from CCS's old forum
Original Post ID: 11025
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: RTC problem with x1226
PostPosted: Mon Jan 27, 2003 1:18 pm     Reply with quote

:=still can not work even i connect battery backup pin to either ground or a backup source. why?
-------------------------------------------------------------

I don't know.

I think you should email the tech support department at Xicor.
Ask them for some sample driver code. I think it's very
likely, that the Engineering department at Xicor has developed
some sample code. It might not be in C. It might be in
in 8051 assembly language. But it doesn't matter. Get that
sample code and study it carefully. Then translate it to C.
Also, ask them for a schematic of a demonstration board for
this chip. Or, any schematic that they have.

Your goal in doing this, is to find out about any small details
that will make the chip work.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11044
MJ
Guest







Re: RTC problem with x1226
PostPosted: Wed Jan 29, 2003 10:23 am     Reply with quote

Have you noticed that RTC registers use BCD coding?

Regards,
MJ
___________________________
This message was ported from CCS's old forum
Original Post ID: 11097
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group