MCP79410 RTC, SPI NOR flash, and Grove connector FeatherWing
You typically insert this FeatherWing in a Adafruit FeatherWing Doubler or Tripler along with your device. It also works in the Particle Ethernet FeatherWing.
One of the limitations of the Gen 3 (nRF52) hardware is that it cannot wake up from SLEEP_MODE_DEEP based on time. That's because the nRF52 real-time-counter does not run in standby sleep mode. Also, when you wake up from SLEEP_MODE_DEEP, the Time object is not set until it's synchronized from the cloud again.
My solution to this is a simple Adafruit FeatherWing board with a MCP79410 real-time clock chip. It's inexpensive ($0.93 in single quantities) and tiny.
Since I had so much room left on the FeatherWing, I also added:
- A CR1220 battery to power the chip with all external power removed (optional)
- 3 Grove expansion connectors (1 digital, 1 analog, 1 I2C, optional)
- A SPI NOR flash memory chip (optional)
Here's a simple program to wake from SLEEP_MODE_DEEP:
#include "MCP79410RK.h"
SerialLogHandler logHandler;
MCP79410 rtc;
void setup() {
// Make sure you call rtc.setup() from setup!
rtc.setup();
}
void loop() {
// Make sure you call rtc.loop() from loop!
rtc.loop();
// Wait 20 seconds after boot to try sleep
if (millis() > 20000) {
if (rtc.setAlarm(10)) {
Log.info("About to SLEEP_MODE_DEEP for 10 seconds");
System.sleep(SLEEP_MODE_DEEP);
}
else {
Log.info("Failed to setAlarm, not sleeping");
delay(10000);
}
}
}
For Gen 2 devices, you might do something like:
System.sleep(SLEEP_MODE_DEEP, 10);
but using the RTC it would be:
if (rtc.setAlarm(10)) {
System.sleep(SLEEP_MODE_DEEP);
}
The reason for the error check around setAlarm is that the alarm can only be set after the RTC has been set to the correct time. Upon cold boot (no 3V3, no battery) the RTC won't be set and sleep cannot be used until the first clock synchronization. This is true even when delaying by seconds.
In the eagle directory are:
- FeatherRTC.sch and FeatherRTC.brd, the EagleCAD files
- FeatherRTC.lbr a library containing all of the parts on this board
- FeatherRTC.pdf, the schematic in pdf format
The MCP79410 library is used for the real-time clock (RTC) chip, and also to access the SRAM and EEPROM features.
There is extensive documentation in that Github for using it. You can find the full browsable API docs here.
You can use a variety of SPI NOR flash chips:
- Winbond, such as a W25Q32.
- Macronix, such as the MX25L8006EM1I-12G
- ISSI, such as a IS25LQ080B.
The SPI chip select (CS) is connected to pin A5.
I recommend the SpiFlashRK to access the flash memory at block level and SpiffsParticleRK library for using the flash as a file system.
Using a Winbond flash chip with SpiFlashRK, you'd declare an object like:
SpiFlashWinbond spiFlash(SPI, A5);
Quantity | Item | Example |
---|---|---|
2 | 14 pf capacitor 0603 | Samsung CL10C140JB8NNNC |
1 | 2.2K resistor 0805 | Panasonic ERJ-6GEYJ222V |
2 | 10K resistor 0603 | Panasonic ERJ-PA3J103V |
1 | 32.768 kHz crystal 9pF | EPSON FC-135 |
1 | MCP79410 RTC | MCP79410-I/SN |
1 | SPI NOR flash memory | Winbond W25Q32JV |
3 | Grove connector PTH vertical | Seeed |
1 | CR1220 battery holder | Keystone 1056TR |
Male header pins 0.1" | Sullins PRPC040SAAN-RC |