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 wang:
回复 Wellin Zhang:
Hi Wellin,
非常感谢!你的解释很给力!
B.R
Wangdaojin
daojin wang:
回复 Wellin Zhang:
Hi Wellin,
非常感谢!你的解释很给力!
B.R
Wangdaojin