在线时间24 小时
UID260346
注册时间2008-6-10
NXP金币0
该用户从未签到
注册会员

- 积分
- 147
- 最后登录
- 2021-10-25
|
我想用KL05的RTC秒中断实现部分功能。1、不调用RTC_INT函数,程序运行正常。
2、调用RTC_INT函数,程序会一直停留在sysint.c中调用 mcg_clk_hz = fei_fee(CLK0_FREQ_HZ,HIGH_GAIN,CLK0_TYPE);时停留在MCG.C 中的红色部分。if (erefs_val)
{
for (i = 0 ; i < 20000000 ; i++)
{
if (MCG_S & MCG_S_OSCINIT0_MASK) break; // jump out early if OSCINIT sets before loop finishes
}
if (!(MCG_S & MCG_S_OSCINIT0_MASK)) return 0x23; // check bit is really set and return with error if not set
}
程序运行不起来,请帮忙看看怎么回事?谢谢!
3、下面是RTC_INT函数:
uint8 RTC_Init(uint32 seconds, uint32 alarm, uint8 c_interval, uint8 c_value,uint8 rtc_irqc, RTC_ISR_CALLBACK isr_func)
{
int i;
SIM_SCGC6 |= SIM_SCGC6_RTC_MASK;
SIM_SOPT1 = SIM_SOPT1_OSC32KSEL(0);
disable_irq(20);
disable_irq(21);
RTC_CR = RTC_CR_SWR_MASK; //rtc 软件复位
RTC_CR &= ~RTC_CR_SWR_MASK;
if (RTC_SR & RTC_SR_TIF_MASK){
RTC_TSR = 0x00000000; // this action clears the TIF
printf("RTC Invalid flag was set - Write to TSR done to clears RTC_SR = %#02X \n", (RTC_SR) ) ;
}
/*Set time compensation parameters*/
RTC_TCR = RTC_TCR_CIR(c_interval) | RTC_TCR_TCR(c_value);
/*Enable the oscillator*/
RTC_CR |= RTC_CR_OSCE_MASK;
/*Wait to all the 32 kHz to stabilize, refer to the crystal startup time in the crystal datasheet*/
for(i=0;i<0x600000;i++);
RTC_SR &= ~RTC_SR_TCE_MASK;
if(rtc_irqc)
{
RTC_IER = (rtc_irqc & 0x07);
RTC_ISR[0]=isr_func;
enable_irq(20);
}
RTC_TSR = seconds;
RTC_TAR = alarm;
RTC_SR |= RTC_SR_TCE_MASK;
return 1;
}
4、下面是我在ISR.H中定义:
#undef VECTOR_036
#define VECTOR_036 RTC_IRQHandler /*!< Vector 36 points to RTC interrupt service routine */
5、在main()函数while()前调用
SMC_PMPROT = SMC_PMPROT_AVLLS_MASK |
SMC_PMPROT_ALLS_MASK |
SMC_PMPROT_AVLP_MASK;
RTC_Init(0, 2, 0, 0, RTC_INT_ALARM,RTC_Handle);
6、中断相关函数:
void RTC_Handle(void)
{
// RTC_TAR +=2; //Alarm register add 2
LED1_TOGGLE;
}
/*
RTC interrupt service function
*/
void RTC_IRQHandler(void)
{
if((RTC_SR & RTC_SR_TIF_MASK)== 0x01)
{
RTC_ISR[0]();
//clear flag
RTC_SR |= RTC_SR_TIF_MASK;
}
else if((RTC_SR & RTC_SR_TOF_MASK) == 0x02)
{
RTC_ISR[0]();
RTC_SR |= RTC_SR_TOF_MASK;
}
else if((RTC_SR & RTC_SR_TAF_MASK) == 0x04)
{
RTC_ISR[0]();
RTC_SR |= RTC_SR_TAF_MASK;
//LED_GREEN_TOGGLE;
LED1_TOGGLE;
}
}
file:///C:\Users\Administrator\AppData\Roaming\Tencent\Users\2250715919\QQ\WinTemp\RichOle\JV7B$VL6G4M0)L)K3$`QXNQ.png
|
评分
-
查看全部评分
|