0

RTC on Itsy Bitsy NRF52840 Express
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RTC on Itsy Bitsy NRF52840 Express

by samuelsam93 on Mon Feb 22, 2021 4:46 pm

Hi,

I'm working on an ultra-low-power gps project using an itsy bitsy nrf52840 express and adafruit ultimate gps. I've gotten the gps functionality working fine, and I'm now trying to save power by implementing a timed interrupt using the rtc so I can put the microcontroller in low power mode when I'm not actively tracking. Basically, I want to put the board in low power mode and set an rtc interrupt to flip the gps on for a couple minutes per hour, record a reading, and then go back into low power mode and wait for another interrupt.

I'm struggling to understand how to even initialize the RTC via the nordic documentation (https://infocenter.nordicsemi.com/index ... __rtc.html) and the Adafruit_nRF52_Arduino github documentation (https://github.com/adafruit/Adafruit_nR ... nrfx_rtc.h). When I try to initialize the rtc with the code below, I get an error: "NRFX_RTC1_INST_IDX was not delcared in this scope".

Code: Select all | TOGGLE FULL SIZE
#include <bluefruit.h>
#include "nrfx_rtc.h"

#define NRFX_RTC_DEFAULT_CONFIG_FREQUENCY 16
#define NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY 2
#define NRFX_RTC1_ENABLED 1

nrfx_rtc_t myRTC = NRFX_RTC_INSTANCE(1);
nrfx_rtc_config_t myRTConfig = NRFX_RTC_DEFAULT_CONFIG;

nrfx_rtc_handler_t myRTChandler(nrfx_rtc_int_type_t NRFX_RTC_INT_COMPARE0){
  Serial.print("hello");
}

void setup() {
  // put your setup code here, to run once:
  nrfx_rtc_init(myRTC*, myRTConfig*, myRTChandler);

}

void loop() {
  // put your main code here, to run repeatedly:
  while(1);
}


I could be doing something totally stupid here, like I said, I'm struggling to follow the documentation. And I understand this code doesn't really do anything right now, but for now I'm really just trying to understand how to initialize the clock. I was able to fix similar errors by just adding the #define statements at the top. But I can't find anything on NRFX_RTC1_INST_IDX except on the Adafruit github. I can post more detailed error messages if that would be helpful. Any help or insight or any example of using the rtc to generate interrupts on the nrf52840 via adafruit's arduino library would be greatly appreciated.

Thanks!

samuelsam93
 
Posts: 1
Joined: Tue Jan 19, 2021 1:29 pm

Re: RTC on Itsy Bitsy NRF52840 Express

by adafruit_support_mike on Mon Mar 01, 2021 1:35 am

I don't think you'll be able to do you want with an ItsyBitsy.

For staters, the term 'real time clock' has several poorly defined and conflicting meanings. The simplest one is just something that reports values in hour:minute:second-day/month/year format. It doesn't make any promises about accurate timekeeping. You can blame its existence on sales/marketing people.

The next step up is the same module connected to a 32,768Hz crystal oscillator. Those are adequate for timekeeping over short intervals, but are subject to drift with temperature and supply voltage noise. Their usual drift is a couple of seconds per day.

From a quick skim of the Nordic documentation, it looks like the nRF52480's peripheral is a bit better than that: it has a prescaler that lets you use a faster oscillator and convert some number of pulses from the oscillator to one 'tick' of the RTC peripheral clock. That's good for reducing jitter from power supply noise.. any errors are averaged out over a larger number of samples, and makes it easier to calibrate the timing to the exact oscillator frequency. It doesn't do much for thermal drift though, so will still have long-term drift of a couple seconds per day.

I'm not sure if you'll be able to use the ItsyBitsy's built-in 32,768Hz crystal for the RTC though. It's already being used to stabilize the CPU clock enough to handle USB communication.

You'll probably need to talk to the folks at Nordic about the details of that.

adafruit_support_mike
 
Posts: 63053
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.