I ordered this Real Time Clock-module from DX a while ago, and I hooked it up yesterday.
I used the example code on the arduino's "Interfacing with hardware" page (the one with the three wire interface), and it worked.
But I can't figure out how to use buttons to adjust the time in the module. I tried to use this:
The only module I found (Recommendations For You - DealeXtreme) doesn't have buttons. So I guess you have to describe what wiring you have. And post the complete code not excerpts, excerpts doesn't help in most cases.
You can add link in your post, just copy the url.
Are you using my code from the Playground section : Arduino Playground - DS1302 ?
That is very basic code. You have to write you own code to fill the structure or you own code to change only the hours.
For example the hour is split into two parts. Let's say the hour is 10. This is split into '1' and '0' and written to the DS1302.
To use a single variable for the hour, some extra programming is needed.
That sketch is only the basic interface to the DS1302 according to the datasheet. It doesn't contain a normal way to write and read the date and time. Sorry, but I have not added that yet.
I'm not familiar with that RTC or the example code relating to it, but from general principles I would have thought it was more sensible to do debouncing, edge detection and clock updates in the main code rather than within an interrupt; that avoids any issues relating to reentrancy, conflicting access to the hardware, and use of code that blocks or involves interrupts from within an interrupt handler. There are plenty of examples showing how to detect and handle switch inputs.
Krodal:
You can add link in your post, just copy the url.
Are you using my code from the Playground section : Arduino Playground - HomePage ?
That is very basic code. You have to write you own code to fill the structure or you own code to change only the hours.
For example the hour is split into two parts. Let's say the hour is 10. This is split into '1' and '0' and written to the DS1302.
To use a single variable for the hour, some extra programming is needed.
That sketch is only the basic interface to the DS1302 according to the datasheet. It doesn't contain a normal way to write and read the date and time. Sorry, but I have not added that yet.
Where in that code do you find an attachInterrupt() statement? You're not using that code, you're using a modified version. Post your code if you wanna get help.
Why do you always set the time to 00:00:00 in your setup? Have your read the comments in your code?
Your hour setter should probably look like this:
// global variables
volatile byte increaseHour = 0;
uint32_t lastMillis = 0;
void uurErbij() {
// do only the absolutely necessary things in the interrupt handler
increaseHour = 1;
}
// replace your loop with this
void loop()
{
ds1302_struct rtc;
char buffer[80]; // the code uses 70 characters.
if (millis() - lastMillis > 5000) {
lastMillis = millis();
// Read all clock data at once (burst mode).
DS1302_clock_burst_read( (uint8_t *) &rtc);
sprintf(buffer, "Time = %02d:%02d:%02d, ", \
(rtc.h24.Hour10 * 10) + rtc.h24.Hour, \
(rtc.Minutes10 * 10) + rtc.Minutes, \
(rtc.Seconds10 * 10) + rtc.Seconds);
Serial.print(buffer);
sprintf(buffer, "Date(day of month) = %d, Month = %d, " \
"Day(day of week) = %d, Year = %d", \
(rtc.Date10 * 10) + rtc.Date, \
(rtc.Month10 * 10) + rtc.Month, \
rtc.Day, \
2000 + (rtc.Year10 * 10) + rtc.Year);
Serial.println(buffer);
}
if (increaseHour) {
DS1302_clock_burst_read( (uint8_t *) &rtc);
rtc.Hour++;
DS1302_clock_burst_write( (uint8_t *) &rtc);
increaseHour = 0;
}
}
This assumes that the debouncing of your button is done in hardware.
I wouldn't use an interrupt to monitor a simple button. With the new loop() version you may find out yourself how you can implement a button monitoring without using interrupts.