Go Down

Topic: Dallas Realtime Clock DS12887 (Read 5577 times) previous topic - next topic


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. :)


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.


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)


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

Code: [Select]

//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.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131