What is the easiest way to mount DS1307 to ethernet shield?
I tried to do this: https://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/wiring-it-up
but my program just freezes when I try to read data from RTC. Is there any other ways to do it?
Code looks like this:
const int RTCpin2 = 2;
const int RTCpin3 = 3;
void setup() {
pinMode(RTCpin2, OUTPUT);
pinMode(RTCpin3, OUTPUT);
analogWrite(RTCpin2, LOW);
analogWrite(RTCpin3, HIGH);
}
void loop() {
// process RTC time
}
Rok Dolinar
asked Dec 8, 2015 at 21:43
-
What do you hope to achieve with that code?Majenko– Majenko2015年12月08日 22:05:08 +00:00Commented Dec 8, 2015 at 22:05
-
this is not the whole code, is bunch of other things too, so I need ethernet shield and then RTC mounter to it.Rok Dolinar– Rok Dolinar2015年12月08日 22:17:20 +00:00Commented Dec 8, 2015 at 22:17
-
Yes, but what do you hope to achieve with that code that you have shown? What do you think it will do?Majenko– Majenko2015年12月08日 22:18:08 +00:00Commented Dec 8, 2015 at 22:18
-
5V to pin3, reading with pin2?Rok Dolinar– Rok Dolinar2015年12月08日 22:54:40 +00:00Commented Dec 8, 2015 at 22:54
-
1Nope, you couldn't be more wrong. I assume those pins are supposed to power the RTC? Well, first you are using the wrong pins, and secondly you are using the wrong functions.Majenko– Majenko2015年12月08日 22:56:23 +00:00Commented Dec 8, 2015 at 22:56
1 Answer 1
I assume that snippet of code is supposed to provide the +5Vand GND for powering the RTC module. Well, there's two fundamental flaws with it:
- Pins 2 and 3 are the DIGITAL pins, not the analog pins. Instead you want to be using pins A2 and A3.
- analogWrite controls the PWM output on pins that support PWM. HIGH is 1, so analogWrite will be providing a 1/255 duty cycle PWM signal on that pin.
So to fix it:
- Use pins A2 and A3 instead of 2 and 3
- Use digitalWrite() instead of analogWrite().
answered Dec 8, 2015 at 23:00
lang-cpp