MCU : NordicSemi nRF51822-QFAC (Using custom board)
SDK Version : 6.1
Softdevice : S110 7.1
Using MDK ARM v4.6
Hi, I want to create a RTC calendar using APP_TIMER, but The time is running FAST。
One day, the time read “9:52” ,when the current real time is “9:40”,
A few days later, the time read “10:03”, when the current real time is “9:47”.
<code>#define APP_TIMER_PRESCALER 0 </code>
void gRtcAppTimerSecondHandle(void * p_context)
{
SoftWareRtcHal *pRTC = (SoftWareRtcHal *)p_context;
pRTC->mSecondCount++;
if(pRTC->mSecondIrq != NULL)
{
pRTC->mSecondIrq(NULL);
}
if((pRTC->mMinuteIrq != NULL) &&
(pRTC->mSecondCount % 60 == 0))
{
pRTC->mMinuteIrq(NULL);
}
if((pRTC->mHourIrq != NULL) &&
(pRTC->mSecondCount % 3600 == 0))
{
pRTC->mHourIrq(NULL);
}
//TRACE_INFO1("*");
}
void gRtcGetDate(SoftWareRtcInterface *RtcInterface, uint32_t RTC_Format,RTC_DateTypeDef* RTC_DateStruct) {
SoftWareRtcHal *pRTC;
RTC_TimeTypeDef mRtcTime;
RTC_DateTypeDef mRtcDate;
if(RtcInterface == NULL)
return;
pRTC = (SoftWareRtcHal *)RtcInterface;
xSeconds2Date(pRTC->mSecondCount, &mRtcDate, &mRtcTime);
memcpy(RTC_DateStruct, &mRtcDate, sizeof(RTC_DateTypeDef));
}
void gRtcGetTime(SoftWareRtcInterface *RtcInterface, uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct){
SoftWareRtcHal *pRTC;
RTC_TimeTypeDef mRtcTime;
RTC_DateTypeDef mRtcDate;
if(RtcInterface == NULL)
return;
pRTC = (SoftWareRtcHal *)RtcInterface;
xSeconds2Date(pRTC->mSecondCount, &mRtcDate, &mRtcTime);
memcpy(RTC_TimeStruct, &mRtcTime, sizeof(RTC_TimeTypeDef));
}
void InitSoftWareRtc(SoftWareRtcInterface *interface){
uint32_t err_code;
SoftWareRtcHal *pRtcHal = (SoftWareRtcHal *)interface;
.............
err_code = app_timer_create(&pRtcHal->mSecondTimerId,
APP_TIMER_MODE_REPEATED,
gRtcAppTimerSecondHandle);
APP_ERROR_CHECK(err_code);
err_code = app_timer_start(pRtcHal->mSecondTimerId,
APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER),
pRtcHal);
APP_ERROR_CHECK(err_code);
..............
}