Pages: 1 [2]   Go Down
Author Topic: Dallas Realtime Clock DS12887  (Read 2903 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks to everyone who provided the valuable information! I have finally got it to work. I am cleaning up code and I will create a wire diagram which I will post to github... unless someone here thinks it would be better hosted somewhere else.

I would like to create a library or maybe add an extension to the existing RTC Library, although it seems that it's specifically I2C based.

If anyone has suggestions I am all ears. smiley
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

DS12887 is so outdated that there is very little value, in my view, to make a library for it.

If you are to make a library, you can make its interface as consistent with the existing rtc libraries so that people can simply swap out the hardware / library and recompile their user code.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know it's an old chip. but for PCB harvesters, it's something cheap and readily available. The great thing about the RTCs on PC motherboards is that they all share a common standard that "should" work. (not to mention an integrated oscillator and battery)
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now that you have it worked out, here is what I do, following the 2nd approach I outlined earlier.

Code:
//write dat to addr
void rtc_write(unsigned char addr, unsigned char dat) {
  digitalWrite(RTC_CS, LOW);   //select the chip
  digitalWrite(RTC_RW, HIGH); digitalWrite(RTC_DS, HIGH);  //ds/rw high
  digitalWrite(RTC_AS, HIGH);  //as high
  RTC_ADDR_PORT = addr;                               //output the address
  RTC_ADDR_DDR = 0xff;             //addr as output
  digitalWrite(RTC_AS, LOW);                   //latch the address
  RTC_DELAY();                     //Pwel 150ns
  digitalWrite(RTC_RW, LOW);                   //enter write mode
  RTC_ADDR_PORT = dat;                                //write the data
  RTC_DELAY();                     //Pwel 150ns
  digitalWrite(RTC_RW, HIGH);                   //write the data
  digitalWrite(RTC_AS, HIGH);      //latch the whole thing
  digitalWrite(RTC_CS, HIGH);      //unselect the chip
  RTC_ADDR_DDR = 0x00;              //adr pins default to input
}

The timing follows the datasheet.

The rtc_read() routine is very similar. You can then build your whole interface based on the read/write routines.
Logged

Pages: 1 [2]   Go Up
Jump to: