为什么使用RTC时间不增加

Home 论坛 一般性讨论 为什么使用RTC时间不增加

正在查看 4 帖子:1-4 (共 4 个帖子)
  • 作者
    帖子
  • #1946
    hehunghehung
    参与者

    使用了板载的RTC,用的例程发现时间并没有增加<!–more–>

     

    int main(void)
    {
    uint32_t sec;
    uint32_t currSeconds;
    uint8_t index;
    rtc_datetime_t date;
    rtc_config_t rtcConfig;

    /* Board pin, clock, debug console init */
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();
    /* Init RTC */
    /*
    * rtcConfig.wakeupSelect = false;
    * rtcConfig.updateMode = false;
    * rtcConfig.supervisorAccess = false;
    * rtcConfig.compensationInterval = 0;
    * rtcConfig.compensationTime = 0;
    */
    RTC_GetDefaultConfig(&rtcConfig);
    RTC_Init(RTC, &rtcConfig);
    /* Select RTC clock source */
    RTC_SetClockSource(RTC);

    PRINTF(“RTC example: set up time to wake up an alarm\r\n”);

    /* Set a start date time and start RT */
    date.year = 2019U;
    date.month = 10U;
    date.day = 25U;
    date.hour = 19U;
    date.minute = 0;
    date.second = 0;

    /* RTC time counter has to be stopped before setting the date & time in the TSR register */
    RTC_StopTimer(RTC);
    /* Set RTC time to default */
    RTC_SetDatetime(RTC, &date);
    /* Enable RTC alarm interrupt */
    // RTC_EnableInterrupts(RTC, kRTC_AlarmInterruptEnable);
    /* Enable at the NVIC */
    // EnableIRQ(RTC_IRQn);
    /* Start the RTC time counter */
    RTC_StartTimer(RTC);

    /* This loop will set the RTC alarm */
    while (1)
    {
    busyWait = true;
    index = 0;
    sec = 0;
    /* Get date time */
    RTC_GetDatetime(RTC, &date);

    /* print default time */
    PRINTF(“Current datetime: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n”,
    date.year,
    date.month,
    date.day,
    date.hour,
    date.minute,
    date.second);

    for(int m = 0;m<10;m++)
    {
    for (int i = 0; i < 800000; ++i)
    {
    __asm(“NOP”); /* delay */
    }
    }
    }
    }

     

    下面是串口收到的时间,并没有增加,已经过了几十秒了,,还是最开始设定的时间

    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00
    Current datetime: 2019-10-25 19:00:00

    #1951
    HowardHoward
    参与者

    板载的RTC指的是什么?芯片内部的RTC吗?请参考下面例子:

    rv32m1_sdk_riscv\boards\rv32m1_vega\driver_examples\rtc

    #1953
    hehunghehung
    参与者

    就是用的这个例程,但是时间并不会增加,用的内部rtc

    #1954
    HowardHoward
    参与者

    怎么可能,你直接编译运行那个例子看看时间能不能变。然后检查一下你的代码,看看个地方有问题。

正在查看 4 帖子:1-4 (共 4 个帖子)
  • 抱歉,回复话题必需登录。