This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RTC0 nrf 52 read counter value

Hi,

I am new to the nrf52. I want to implement the code that gives me current date and time value based on default set values.

for this i need to read the current counter value. Can any one tell me the simplest way to read the current counter value in RTC0?

Also is there any sample code related to date and time calculation in nrf52??

Please give reply.!!!!

Parents
  • Hi,

    First I must stress that the real time counter (RTC) is a timer. It is not, as the abbreviation "RTC" may suggest, a real time clock. However, it runs off the 32 kHz clock and can be used to keep track of time within the accuracy of that clock signal.

    You will find that the Real Time Counter Example of the latest SDK uses RTC on the nRF52.

    For date and time calculation I suggest that you use an existing time and date library, since there are a lot of pitfalls when working with time and date. I think the ctime standard c library would be a good choice. Most likely the time_t format will be a unix timestamp and it should be safe to increment a "current time" value of this type every second to keep it up to date.

    Regards, Terje

  • You probably haven't started a Low Frequency Clock, without one of those started, the counter doesn't count. You can start the RC one (pretty inaccurate) or the XTAL one (if there's a crystal mounted) which is more accurate. However, you have to start some LF clock.

    Usually this is taken care of by the softdevice initialisation as that needs an LF clock source, however if you're not using a softdevice, ie no bluetooth, then nothing else is running one.

Reply
  • You probably haven't started a Low Frequency Clock, without one of those started, the counter doesn't count. You can start the RC one (pretty inaccurate) or the XTAL one (if there's a crystal mounted) which is more accurate. However, you have to start some LF clock.

    Usually this is taken care of by the softdevice initialisation as that needs an LF clock source, however if you're not using a softdevice, ie no bluetooth, then nothing else is running one.

Children
No Data
Related