Raspberry Pi and RTC alarm – initial prototype

One of the challenges I have been trying to work out is how to use the alarm of a real-time clock to boot a Raspberry Pi once it has been shut down.  I have been using DS3231 RTCs, which integrate easily with Raspberry Pi via I2C.  The DS3231 also has a pin (INT/SQW), one of whose functions is to indicate that an alarm has activated.

Recent Raspberry Pis (A+ and B+ models and the Zero) have a reset jumper.  If you short the two pins of the jumper (one of the pins is ground) it will reset the Pi if it is running, or if it was previously shit down, it will restart when the jumper is shorted.  Now, if you can link the output of the alarm on a RTC to the reset jumper on a Pi, it becomes possible to set an alarm on the RTC and then shut the Pi down so that it can boot up again when the alarm on the RTC is activated…..

The circuitry of the reset jumper can be found on the Raspberry Pi schematics:

Reset Circuit

Basically, during normal operation, the RUN pin on the BCM is held high.  Shorting the reset jumper pulls it low, causing the Pi to (re)start when it goes high again.  The important thing to note is the 100nF debounce capacitor (C14).  That means that any automated system for pulling the RUN pin low needs to do so for long enough for C14 to discharge.

A second challenge is that the INT pin on the DS3231, while it is pulled low when an alarm occurs, does not return to high until a register on the DS3231 is reset.  This can only be done while the Pi is running!  To allow the Pi to boot, the voltage that is being applied to the RUN pin needs to be returned to 3.3V in order to allow the Pi to start running again.  The solution that I found to this problem is to insert a negative edge detector between the RTC and the reset jumper.

My initial attempt at building a negative edge detector failed.  I was only using gates in the circuit, and these did not introduce enough propagation delay in order to hold the output low long enough to allow C14 to discharge, which would allow RUN to be pulled low. The solution to fix this was to use a capacitor to introduce propagation delay, resulting in the following circuit:


The NOR gates which have one input pulled down act as inverters.  The capacitor and resistor between the first and second gate effectively add propagation delay to the circuit.

Under normal circumstances, the output of the left-most gate is low.  As a result, the capacitor will remain discharged, and the lower input to the second gate will remain low.  The NOR operation with the high input will result in a low output, which is negated by the final gate, making it’s output normally remain high.

When the INT pin of the RTC is pulled low as a result of an alarm, initially both inputs to the second gate will be low, resulting in the output being high, which is inverted to give low output from the last gate.  This pulls the RUN pin on the BCM low (after C14 discharges).  The left-most gate will however now have a high output, which will begin to charge the capacitor.  Once it has charged, the lower input to the last gate will be high, resulting in its output going low – providing the second edge of the pulse.  This output is inverted, bringing the final output back high, and returning the RUN pin to a high state.

The circuit was initially built using capacitors I had lying around, the smallest available being a 470nF capacitor.  That was mated with a 100kΩ resistor.  This resulted in a pulse which was long enough to be visible from a LED that was connected to the output of the circuit.