This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

关于TM4C123GH6PM 的RTC使用疑问

Other Parts Discussed in Thread: TM4C123GH6PM

1.  在使用RTC时,先要将RTC分频为1HZ, 这个寄存器我已找到了(Register 22: GPTM RTC Predivide (GPTMRTCPD), offset 0x058),但是Firmware中使用哪个函数去设置呢?

2. 在使用RTC时,预加载一个计数匹配置,这里是要加载到“GPTM Timer A 匹配寄存器(GPTMTAMATCHR),偏移量 0x030” 还是“GPTM Timer B 匹配寄存器(GPTMTBMATCHR),偏移量 0x034”。

我的目的是要做一个1S的周期定时,准备触发AD一秒采集一次数据(暂没加进去),同时方便后面做万年历。

以下跟据TI例程更改RTC配置,不知配置是否还有问题?

#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"


int main(void)
{
 //uint32_t ui32Period;

 // To set system clock is 40Mhz and used the PLL and External 16Mhz
 SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
 GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

 SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
 TimerConfigure(TIMER0_BASE, TIMER_CFG_RTC);            //TIMER_CFG_PERIODIC);

 //ui32Period = (SysCtlClockGet() / 10) / 2;
 //TimerLoadSet(TIMER0_BASE,TIMER_A, ui32Period -1); //TIMER_O_TAMATCHR
 TimerMatchSet(TIMER0_BASE,TIMER_A, 2);    // Load value to GPTM Timer A Match -->GPTMTAMATCHR

 IntEnable(INT_TIMER0A);
 TimerIntEnable(TIMER0_BASE, TIMER_RTC_MATCH);        // Enable "RTCIM"
 IntMasterEnable();

 //TimerEnable(TIMER0_BASE, TIMER_A);
 TimerRTCEnable(TIMER0_BASE);   // "RTCEN=1" of GPTMCTL

 while(1)
 {
 }
}

void Timer0IntHandler(void)
{
 // Clear the timer interrupt
 // TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
 TimerIntClear(TIMER0_BASE, TIMER_RTC_MATCH);     // Clear the RTC interrupt, Via clear The RTCCINT bit of GPTMICR

 // Read the current state of the GPIO pin and
 // write back the opposite state
 if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
 {
  GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
 }
 else
 {
  GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
 }
}

  • Daojin,

    1. GPTM的RTC模式中,是自动将32.768KHz的时钟分频成1Hz的时钟,无需设置分频值。寄存器(Register 22: GPTM RTC Predivide (GPTMRTCPD), offset 0x058)是一个只读寄存器。

    2.当timer设置为RTC模式时,Time A和Time B将工作在组合模式,即组合成一个32位(16/32 Timer)或者64位(32/64 Timer)counter. 因此,具体的设置方法参考datasheet里面的 Accessing Concatenated 16/32-Bit GPTM Register Values和Accessing Concatenated 32/64-Bit Wide GPTM Register Values章节。在调用相关API函数设置时,使用TIMER_A参数即可。

    3.使用TIMER的RTC模式是,需要在CCP0输入32.768KHz的时钟信号。

    另外,如果想要制作万年历,建议使用Hibernation模式下的RTC。具体的例程参考TIVAWARE下的Hibernation工程.

    best ragards

    Wellin Zhang

  • 另外补充一点,使用ccp0输入32.768KHz时钟时,要配置相应的IO口。

    附件是基于123G launchpad的测试程序,PD0输出32.768KHz的PWM,PB6为CCP0输入。

    将Launchpad的PD0和PB6连在一起即可测试。

    LED将以1Hz的频率闪烁。另外,会通过串口输出相关的match寄存器的值。

    Best Regards

    Wellin Zhang

    timers.zip
  • Hi Wellin,

    非常感谢!你的解释很给力!

    B.R

    Wangdaojin

  • Hi Wellin,

    非常感谢!你的解释很给力!

    B.R

    Wangdaojin