Example RTC with sleep not working correctly I think

Good day. I am using the ARtemis Blackboard Nano and the current RTC with sleep example. The default sleep time of 200o ms is not working as planned rather the serial window output is cycling with new times as quickly as it can.

For example, from my serial output window:

It is now 8:43:29.55 07/15/20 Day of week: 3 = Wednesday

It is now 8:43:29.56 07/15/20 Day of week: 3 = Wednesday

It is now 8:43:29.56 07/15/20 Day of week: 3 = Wednesday

It is now 8:43:29.57 07/15/20 Day of week: 3 = Wednesday

It is now 8:43:29.57 07/15/20 Day of week: 3 = Wednesday

It is now 8:43:29.58 07/15/20 Day of week: 3 = Wednesday

It is now 8:43:29.58 07/15/20 Day of week: 3 = Wednesday

I have tried changing the sleep wake interval but again no effect. I am using for testing purposes: uint32_t msToSleep = 4000; ,

I have not changed any other part of the code for testing. And in any case the unchanged example behaves in the same way.

Code is:

#include "RTC.h" //Include RTC library included with the Aruino_Apollo3 core
APM3_RTC myRTC; //Create instance of RTC class

//uint32_t msToSleep = 2000; //This is the user editable number of ms to sleep between RTC checks

uint32_t msToSleep = 4000; //This is the user editable number of ms to sleep between RTC checks


#define TIMER_FREQ 3000000L //Counter/Timer 6 will use the HFRC oscillator of 3MHz
uint32_t sysTicksToSleep = msToSleep * (TIMER_FREQ / 1000);

void setup()
{
  Serial.begin(115200);
  Serial.println("SparkFun RTC Example");

  myRTC.setToCompilerTime(); //Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
  //myRTC.setTime(7, 28, 51, 0, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM

  setupWakeTimer();
}

void loop()
{
  myRTC.getTime();

  Serial.printf("It is now ");
  Serial.printf("%d:", myRTC.hour);
  Serial.printf("%02d:", myRTC.minute);
  Serial.printf("%02d.", myRTC.seconds);
  Serial.printf("%02d", myRTC.hundredths);

  Serial.printf(" %02d/", myRTC.month);
  Serial.printf("%02d/", myRTC.dayOfMonth);
  Serial.printf("%02d", myRTC.year);

  Serial.printf(" Day of week: %d =", myRTC.weekday);
  Serial.printf(" %s", myRTC.textWeekday);

  Serial.println();

  am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP); //Sleepy time
}

//We use counter/timer 6 for this example but 0 to 7 are available
//CT 7 is used for Software Serial. All CTs are used for Servo.
void setupWakeTimer()
{
  //Clear compare interrupt
  am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG); //Use CT6

  am_hal_stimer_int_enable(AM_HAL_STIMER_INT_COMPAREG); // Enable C/T G=6

  //Don't change from 3MHz system timer, but enable G timer
  am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
  am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ | AM_HAL_STIMER_CFG_COMPARE_G_ENABLE);

  //Setup ISR to trigger when the number of ms have elapsed
  am_hal_stimer_compare_delta_set(6, sysTicksToSleep);

  //Enable the timer interrupt in the NVIC.
  NVIC_EnableIRQ(STIMER_CMPR6_IRQn);
}

//Called once number of milliseconds has passed
extern "C" void am_stimer_cmpr6_isr(void)
{
  uint32_t ui32Status = am_hal_stimer_int_status_get(false);
  if (ui32Status & AM_HAL_STIMER_INT_COMPAREG)
  {
    am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG);

    //Reset compare value. ISR will trigger when the number of ms have elapsed
    am_hal_stimer_compare_delta_set(6, sysTicksToSleep);
  }
}

Regards

That’s odd. I am not familiar with the RTC library, however some new features are pending in a pull request on GitHub. If you are familiar with Git / GitHub Desktop you could try out those features by replacing your Arduino Apollo3 package with the git repo and switching to that pull request branch.

https://github.com/sparkfun/Arduino_Apollo3/pull/170

Will try and will report results.

Thank you


```I deleted the original Sparkfun Apoilo3 library and changed the github line in Arduino preferences. Re-installed the Apollo board, chose the Sparkfun Artemis nano (red) and loaded the RTC with sleep demo file from the menu. I also switched to an Artemis nano red board instead of the black board nano just to make sure it wasn't a black versus red issue.

No change, the serial output is still cycling every 3 or 4 milliseconds. I even changed the sleep time interval to:

uint32_t msToSleep = 400000;


The serial display is still cycling every 3 or 4 milliseconds.

Where to now?

Regards

You won’t be able to get those changes through the Arduino boards manager yet. It would require using Git and replacing the old version. Alternatively those changes will be released in v1.1.2 which will be available in the Arduino manager soon. Keep an eye out.

Anyone else with more experience with the RTC library is encouraged to reply as well!

Ok, understood. I will wait for the new version update.

Thank you.

Hey there, just wanted to let you know that v1.1.2 is released and contains the RTC improvements! Give it a shot and let us know how it goes

Artemis thing plus: RTC deepsleep in version 1.1.2 is not working (still). Previous version was ok.

The code

am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP); //Sleepy time

does not put the uP to sleep at all; even without the wak-up interrupt, the code simply continues.

@jur123@xs4all.nl that appears to be an issue with the underlying HAL usage.

Can you provide more info? What changed from the version that was working?

Ok, just updated to 1.1.2 and tried various RTC examples including the Low Power Alarm example. Judging from the serial display it seems to work now. However, I cannot speak to whether

am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP); //Sleepy time

is working as desired as jur123 points out above.

Regards