首页 论坛 原厂专区 NXP(freescale) MCU 【经验分享】RTC_TSR寄存器读出不正确,咋回事?

发帖 回复

[分享] 【经验分享】RTC_TSR寄存器读出不正确,咋回事?
346 查看
0 回复
 楼主 | 发布于 2020-09-28 | 只看楼主
分享到:
客户问题介绍:
·        芯片型号:MK60DN512ZVMD10
·        描述:在程序中,连续不断的读取RTC_TSR寄存器值,并将结果传给上位机,但发现连续读出的值出现前后不匹配的问题,从理论上分析,RTC_TSR寄存器内的值应该逐渐递增的,但从打印的输出结果看,存在个别前后不一致的现象(如图1所示),所以怀疑这是不是芯片的Bug呢?

1

1

            #include   
            #include   
            #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寄存器之前,添加一个延时函数,经过一段时间的测试后,发现出错的频率虽然没有原来那么多,但还是会出现,看来这是个治标不本的方法啊,只能另想方法啊。
(0 ) (0 )
回复 举报
  • 发表回复
    0/3000





    举报

    请选择举报类别

    • 广告垃圾
    • 违规内容
    • 恶意灌水
    • 重复发帖

    全部板块

    返回顶部