cancel
Showing results for 
Search instead for 
Did you mean: 

How to keep track of time while sleeping on SPBTLE / BlueNRG-1 devices

RGilh.1
Associate

In order to keep track of the Time of Day I would like to implement a time tick.

None of the timers run (other than the virtual timer) when the bluetooth module goes into low power mode. I would like the CPU to only wake up when there is an external event or one of the virtual timers expire. I do not want the virtual timer to wake the entire CPU just to keep incrementing a timer every second.

Is there a method to determine elapsed time from the slow running oscillator

The following does not seem to work consistently.

        preSleep = HAL_VTimerGetCurrentTime_sysT32();

        BlueNRG_Sleep(sleepMode, WAKEUP_IO10, wakeup_level);

        postSleep = HAL_VTimerGetCurrentTime_sysT32();

        diff = HAL_VTimerDiff_ms_sysT32(postSleep,preSleep);

        incTimeStamp(diff);

7 REPLIES 7
WLipi.1
Associate II

Hi, have you found an answer for this question? I am interested too

Scott Löhr
Senior II

Well, the answer to your question depends on what host processor you are running on. If you are using an STM32 MCU, then you need to initialize, run and use the RTC module.

In my case bluenrg-2 is host (standalone SoC Mode) and unfortunately as far as I know there is no RTC in low power mode. Hence need to use virtual timer. I wonder if this is accurate enough to track time for longer periods.

Scott Löhr
Senior II

Did you RTFM, or am I missing something?

Incredulous at your response, I just downloaded the BlueNRG-2 datasheet and I see that the RTC ticks in sleep mode and that sleep mode gets you down to 2.1-uA

No need to be rude. Looking at examples provided by st https://www.st.com/resource/en/user_manual/dm00298232-bluenrg1-bluenrg2-development-kits-stmicroelectronics.pdf '20.9 RTC examples' I can see that RTC in sleep mode is only simulated by virtual timer. At least thats what API in DK is supporting, no wake-up source from rtc. If you could prove otherwise I would be happy as I would like to use this functionality...

Scott Löhr
Senior II

No intention to be impolite, but I do get frustrated by lazy posts clogging up the community, so my rhetorical questions can be blunt.

Anyway, it looks like your BlueNRG-2 is based on the Cortex-M0, so you could download the STM32CubeM0 and look for HAL and Low Level examples of running the RTC.

RGilh.1
Associate

Guys calm down!

So my question was originally posted for the BlueNRG-1 devices and the RTC does NOT tick down in sleep mode. I ended up using the virtual timer to check the elapsed time based on the system tick. I would then increment my CPU RTC manually based on the system tick. I had set the Bluetooth ADV interval to 10 seconds. Using this method I was able to maintain 2 seconds accuracy over 60 minutes at least.

I did take into account that the VTimers overflow every 52 seconds or so hence the ADV interval of 10 seconds.

msSinceStart = HAL_VTimerDiff_ms_sysT32(HAL_VTimerGetCurrentTime_sysT32(),sysTimeStart);