【经验分享】RTC_TSR寄存器读出不正确,咋回事?
本帖最后由 FSL_TICS_Robin 于 2014-7-18 14:11 编辑客户问题介绍:
• 芯片型号:MK60DN512ZVMD10
• 描述:在程序中,连续不断的读取RTC_TSR寄存器值,并将结果传给上位机,但发现连续读出的值出现前后不匹配的问题,从理论上分析,RTC_TSR寄存器内的值应该逐渐递增的,但从打印的输出结果看,存在个别前后不一致的现象(如图1所示),所以怀疑这是不是芯片的Bug呢?
图1
表1
#include <stdio.h>
#include <drivers/uart/uart.h>
#include "cmd_rtcdebug.h"
#include "common.h"
extern "C"
{
#include "wdog.h"
}
extern "C"
int cmd_rtcdebug(const char *args)
{
uint32_t lowestValue;
uint32_t lastFailValue = 0;
uint32_t failCountInRow = 0;
int wdCount = 0;
lowestValue = RTC_TSR;
printf("press any key to exit\r\n");
while(1)
{
uint32_t nextValue = RTC_TSR;
if (uart_kbhit())
{
break;
}
if (nextValue < lowestValue)
{
if (lastFailValue != nextValue)
{
printf("RTC fail: lowest value: %u, next value: %u\r\n", lowestValue, nextValue);
}
lastFailValue = nextValue;
failCountInRow++;
}
else if (nextValue == lowestValue)
{
if (failCountInRow)
{
printf("RTC fails in row: %u\r\n", failCountInRow);
failCountInRow = 0;
}
}
else if (nextValue > lowestValue)
{
if (failCountInRow)
{
printf("RTC fails in row: %u\r\n", failCountInRow);
failCountInRow = 0;
}
if (wdCount > 300)
{
wdog_refresh();
wdCount = 0;
}
wdCount++;
printf("RTC_TSR: %u\r\n", nextValue);
lowestValue = nextValue;
}
}
return 0;
}
针对第一个猜测,在查阅Errata文档后,大致可以排除;至于第二个猜测,我应对的方法是在每次读取RTC_TSR寄存器之前,添加一个延时函数,经过一段时间的测试后,发现出错的频率虽然没有原来那么多,但还是会出现,看来这是个治标不本的方法啊,只能另想方法啊。
各位网友有没有好的想法,欢迎来讨论!
PS:本帖可从飞思卡尔版块置顶帖:飞思卡尔Kinetis资料大本营的飞思卡尔论坛支持小组【经验分享】帖汇总链接进入。 欢迎大伙积极来论坛交流哦! 本帖最后由 FSL_TICS_ZP 于 2014-4-30 10:28 编辑
看来大家的讨论不积极啊,答案揭晓!
在咨询过AE部门后,发现问题的根源是K60的参考没有给出读取RTCRTC_TSR需要注意的细节。而在K64的参考手册却有这么一段话(如下所示),而问题也就迎仍而解啊!
页:
[1]