I got some spare DS1302 chips that I'd like to connect to my Raspberry Pi to use as a RTC, but I'm not so sure how to. How would I go about it?
Asked
Active
Viewed 3,173 times
1 Answers
3
Using the guide from hobbytronics as a reference, with this module i got from Cytron
1. Connect it to the RPi's GPIO
RST (CE) -> GPIO#17
I/O (DAT) -> GPIO#18
SCLK (CLK) -> GPIO#21
GND -> GND
VCC -> 3v
2. compile source
cc rtc-pi.c
this is for the rev 1 board, mine was the rev 2 so i had to update the definitions in the source:
#define SCLK_OUTPUT *(gpio+GPIO_SEL2) &= 0xFF1FFFFFL; *(gpio+GPIO_SEL2) |=0x00200000L
#define SCLK_HIGH *(gpio+GPIO_SET) = 0x08000000L
#define SCLK_LOW *(gpio+GPIO_CLR) = 0x08000000L
3. execute the compilation
output from the compilation would be a a.out file, rename it to rtc-pi and set the date with something like this
sudo ./rtc-pi 20131216175500
or to set it from the current time
sudo ./rtc-pi `date +"%Y%m%d%H%M%S"`
this will set the time. now all you need to do is to invoke it during every startup to keep the date
sudo ./rtc-pi
Misc
to quote the guide from hobbytronics
I also found that a pullup resistor is needed between DAT and VCC (= 3.3V). A 10k..30k resistor seems to work fine.
Now i didn't do this at the moment because i don't have any resistors with me, not so sure about the impact of it.
Ivan
- 91
- 1
- 7