View previous topic :: View next topic |
Author |
Message |
KaraMuraT
Joined: 16 May 2006 Posts: 65 Location: Ankara/Turkey
|
Did anyone work with Seiko RTCs? |
Posted: Fri Feb 16, 2007 12:56 am |
|
|
Hi,
I'm using Seiko S35390A Real Time Clock in the new project. This one is the lowest power RTC I know. (Typical: 250nA @3.3V, 400nA @5V).
But I have problems with it. I can access via I2C, set registers and read them back properly, except real time data register. And as you can guess the most important register.
Whether I set it or not, I get same garbage data. Have anyone worked with Seiko RTCs?
Let me paste the code here...
P.S: You'll see a ReverseInt function, which is not normal in I2C communcations. Unfortunately Seiko sends and receives LSB first, not the MSB. That's why I used this function.
P.S.2: Datasheet address if required: ftp://ftp.sii.co.jp/pub/ic/speed_dt/dt_sht_e/assp/S35390A_E.pdf
Code: |
#use i2c(MASTER, SCL=PIN_C3,SDA=PIN_C4, SLOW, FORCE_HW)
#define RTC_IC 0x60 /// Fixed Seiko S35390A I2C address start
#define REG_STAT_1 0x00 /// All values 1 bit shifted to left
#define REG_STAT_2 0x02
#define RTC_DATA_1 0x04
#define RTC_DATA_2 0x06
#define REG_INT_1 0x08
#define REG_INT_2 0x0A
#define REG_CLK_ADJ 0x0C
#define REG_FREE 0x0E
#define I2C_WR 0x00
#define I2C_RD 0x01
unsigned int ReverseInt(unsigned int value)
{
unsigned int reversed;
unsigned int rc; /// just a counter
for(rc=0;rc<8;rc++)
{
if(bit_test(value, rc)) bit_set(reversed, 7 - rc);
}
return reversed;
}
void RTCSetDateTime()
{
MtrDateTime.yr = ReverseInt(MtrDateTime.yr);
MtrDateTime.mth = ReverseInt(MtrDateTime.mth);
MtrDateTime.day = ReverseInt(MtrDateTime.day);
DayOfWeekNow = ReverseInt(DayOfWeekNow);
MtrDateTime.hr = ReverseInt(MtrDateTime.hr);
MtrDateTime.min = ReverseInt(MtrDateTime.min);
SecondsNow = ReverseInt(SecondsNow);
i2c_start();
i2c_write(RTC_IC | RTC_DATA_1 | I2C_WR); ///Accessing to Real Time Data Register.
i2c_write(MtrDateTime.yr);
i2c_write(MtrDateTime.mth);
i2c_write(MtrDateTime.day);
i2c_write(DayOfWeekNow);
i2c_write(MtrDateTime.hr);
i2c_write(MtrDateTime.min);
i2c_write(0x00); /// set seconds to zero
i2c_stop();
}
void RTCReadDateTime()
{
///Accessing to Real Time Data Register
i2c_start();
i2c_write(RTC_IC | RTC_DATA_1 | I2C_RD);
MtrDateTime.yr = i2c_read();
MtrDateTime.mth = i2c_read();
MtrDateTime.day = i2c_read();
DayOfWeekNow = i2c_read();
MtrDateTime.hr = i2c_read();
MtrDateTime.min = i2c_read();
SecondsNow = i2c_read(0);
i2c_stop();
/// Reverse the incoming Data (explained at page top)
MtrDateTime.yr = ReverseInt(MtrDateTime.yr);
MtrDateTime.mth = ReverseInt(MtrDateTime.mth);
MtrDateTime.day = ReverseInt(MtrDateTime.day);
DayOfWeekNow = ReverseInt(DayOfWeekNow);
MtrDateTime.hr = ReverseInt(MtrDateTime.hr);
MtrDateTime.min = ReverseInt(MtrDateTime.min);
SecondsNow = ReverseInt(SecondsNow);
/// Mask necessary values
MtrDateTime.mth &= 0b00011111;
MtrDateTime.day &= 0b00111111;
DayOfWeekNow &= 0b00000111;
MtrDateTime.hr &= 0b00111111;
MtrDateTime.min &= 0b01111111;
SecondsNow &= 0b01111111;
}
|
_________________ /// KMT
/// www.muratursavas.com |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Feb 16, 2007 9:58 am |
|
|
The ReverseInt() function has a bug; you are only setting bit values when they are '1', not clearing any values. This will only work when the start value of 'reversed' is initialized to zero.
Change Code: | unsigned int reversed; | to Code: | unsigned int reversed = 0; |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Feb 16, 2007 12:27 pm |
|
|
You might want to have a look at http://www.ccsinfo.com/forum/viewtopic.php?p=76547 where I just placed a comparison of several bit-order reverse routines. Your routine uses an average of 374 instruction cycles while the fastest routine published there can achieve the same result in just 24 instruction cycles. |
|
|
KaraMuraT
Joined: 16 May 2006 Posts: 65 Location: Ankara/Turkey
|
|
Posted: Sat Feb 17, 2007 11:41 am |
|
|
Thank you ckielstra,
The routine was not really checked. It was written for a quick test after the response of a Seiko Engineer.
I was planning to rewrite it after solving the I2C data acqusition problem, but you helped me to process it faster. Thank you.
Also do you got any idea about this I2C problem?. you may never used seiko RTC but I'm open for any thoughts. Because I've ran out of ideas... _________________ /// KMT
/// www.muratursavas.com |
|
|
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
|
|
Posted: Sun Feb 18, 2007 4:42 pm |
|
|
If you can read and write to other registers successfully, then there
is probably no i2c problem.
For testing, try reading the raw data without reversing the bit order
or masking the data bits. See if the data makes sense keeping in mind
that the data is in packed bcd format, not binary, and the bits are in reverse order.
BTW the Philips PCF8563 is an RTC that consumes about the same current
Last edited by Kenny on Mon Feb 19, 2007 8:58 am; edited 1 time in total |
|
|
KaraMuraT
Joined: 16 May 2006 Posts: 65 Location: Ankara/Turkey
|
|
Posted: Mon Feb 19, 2007 12:34 am |
|
|
Thanks for the heads up Kenny. I totally forgot about PCF8563. Think that it has higher consumption. I got samples and try it today.
Tha data "was" making sense. It was working after reset and increased the time starting to this value: 00 01 01 01 01 01.
But I never had a chance to set it to an another time. If I try it just turns to meaningless time. For example the data must be in BCD format, and returns like 3F. But maybe the reversing function is not right. That's why its not functioning well.
I'll try the PCF8563, and if it works fine, I'll never look back to seiko as RTC. (But I recommend to use their voltage regulators due to low power consumption) _________________ /// KMT
/// www.muratursavas.com |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Feb 19, 2007 2:13 am |
|
|
Quote: | But maybe the reversing function is not right. That's why its not functioning well. | I had a look at your program and at the RTC datasheet; I agree with Kenny that it is very likely your problem is not I2C related.
Have you tried my correction to your reverse function? Without the fix you will send to and receive garbage data from the RTC. |
|
|
KaraMuraT
Joined: 16 May 2006 Posts: 65 Location: Ankara/Turkey
|
|
Posted: Mon Feb 19, 2007 3:00 am |
|
|
I just tried NXP PCF8563 it and works fine with 1/100 effort comparing Seiko S35390A. Now Seiko RTC is history for me.... Welcome PCF8563
I'll test it later in a spare time with Seiko, and inform you. Just removed the IC and don't want to waste time with resoldering. I'm really running out of time. _________________ /// KMT
/// www.muratursavas.com |
|
|
KaraMuraT
Joined: 16 May 2006 Posts: 65 Location: Ankara/Turkey
|
|
Posted: Tue Feb 20, 2007 12:27 am |
|
|
And let me aware you something about seiko rtc. if you try to get the time in every second it does not answer you. Needs at least 2 seconds between communication. Is it normal? No... I didn't expect something like this and still don't. But it behaves so.
With PCF8563, I'm getting the real time data every second, and works just fine... _________________ /// KMT
/// www.muratursavas.com |
|
|
PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
|
Posted: Tue Feb 20, 2007 7:14 am |
|
|
You might give DS1307 a try too |
|
|
KaraMuraT
Joined: 16 May 2006 Posts: 65 Location: Ankara/Turkey
|
|
Posted: Wed Feb 21, 2007 1:58 am |
|
|
Thanks for the advice but I'll stick to PCF8563. It has Alarm functions, and countdown timer and square wave output. DS1307 has square wave output and switch circuitry. Our product is battery powered and does not need switch circuitry. And I need alarm functions for non-linear (not periodic) workflow. This minimizes power consumption dramatically.
And also DS1307 is %106 expensive comparing to PCF8563
(0.66 USD / 1.36 USD) _________________ /// KMT
/// www.muratursavas.com |
|
|
PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
|
Posted: Wed Feb 21, 2007 3:25 am |
|
|
10x for the last info |
|
|
|