From: Richard Klingler (richard@klingler.ch)
Date: Thu Sep 05 2002 - 05:33:10 EDT
Hi Greg
Thanx...but had to modify that it actually reads anything else but '1's (o;
The tricky thing with the ds1302 is that you have to read the bit
before the clock goes high. Also the first bit is sended out on the
falling clock edge of a write, so the read is now put actually in
front of the clock_high/clock_low commands (o;
original code:
unsigned int ds1302_recvbits(void)
{
unsigned int val;
int i;
for (i = 0, val = 0; (i < 8); i++) {
*ds1302_dp |= RTC_SCLK;
val |= (((*ds1302_dp & RTC_IODATA) ? 1 : 0) << i);
*ds1302_dp &= ~RTC_SCLK;
}
return(val);
}
modified to:
unsigned int ds1302_recvbits(void)
{
unsigned int val;
int i;
for (i = 0, val = 0; (i < 8); i++) {
val |= (((*ds1302_dp & RTC_IODATA) ? 1 : 0) << i); // must read before
*ds1302_dp |= RTC_SCLK; // clock high
*ds1302_dp &= ~RTC_SCLK; // clock low
}
return(val);
}
greetings from .fi (o;
Rick
Richard Klingler mail: richard@klingler.ch
Keltasirkunpolku 1b B62 http://www.klingler.ch/
20610 Turku, Finland phon: +358 40 7484711
This message resent by the uclinux-dev@uclinux.org list server http://www.uClinux.org/
This archive was generated by hypermail 2.1.4 : Thu Sep 19 2002 - 13:21:49 EDT