CC2541无外部32.768K晶振,WatchDog只在两种时间下起作用,分别为:15.625 ms和1.9ms
CC2541无外部32.768K晶振,WatchDog只在两种时间下起作用,分别为:15.625 ms和1.9ms,各初始化函数为:
系统时钟初始化函数:
// switch to the 16MHz HSOSC and wait until it is stable
#define SET_OSC_TO_HSOSC() \
{ \
CLKCONCMD = (CLKCONCMD & 0x80) | CLKCONCMD_16MHZ; \
while ( (CLKCONSTA & ~0x80) != CLKCONCMD_16MHZ ); \
}
// switch to the 32MHz XOSC and wait until it is stable
#define SET_OSC_TO_XOSC() \
{ \
CLKCONCMD = (CLKCONCMD & 0x80) | CLKCONCMD_32MHZ; \
while ( (CLKCONSTA & ~0x80) != CLKCONCMD_32MHZ ); \
}
// set 32kHz OSC and wait until it is stable
#define SET_32KHZ_OSC() \
{ \
CLKCONCMD = (CLKCONCMD & ~0x80) | OSC_32KHZ; \
while ( (CLKCONSTA & 0x80) != OSC_32KHZ ); \
}
/* The OSC_PD register is not documented in the user guide.
It is meant to be used by TI only */
#define START_HSOSC_XOSC() \
{ \
SLEEPCMD &= ~OSC_PD; /* start 16MHz RCOSC & 32MHz XOSC */ \
while (!(SLEEPSTA & XOSC_STB)); /* wait for stable 32MHz XOSC */ \
}
#define STOP_HSOSC() \
{ \
SLEEPCMD |= OSC_PD; /* stop 16MHz RCOSC */ \
}
/* Board Initialization */
#define HAL_BOARD_INIT() \
{ \
/* Set to 16Mhz to set 32kHz OSC, then back to 32MHz */ \
START_HSOSC_XOSC(); \
SET_OSC_TO_HSOSC(); \
SET_32KHZ_OSC(); \
SET_OSC_TO_XOSC(); \
STOP_HSOSC(); \
\
/* Enable cache prefetch mode. */ \
PREFETCH_ENABLE(); \
}
初始化看门狗:
void InitWatchdog(void)
{
halIntState_t _sReg;
HAL_ENTER_CRITICAL_SECTION(_sReg);
WDCTL = 0x00; //打开IDLE
WDCTL |= 0x02; //15.625 ms复位
WDCTL |= BV(3); //开启watchdog模式
HAL_EXIT_CRITICAL_SECTION(_sReg);
}
用1s或250ms时看门狗不复位
喂狗函数:
void FeedWatchDog(void)
{
halIntState_t _sReg;
HAL_ENTER_CRITICAL_SECTION(_sReg);
WDCTL = (0xA0 | WDCTL & 0x0F);
WDCTL = (0x50 | WDCTL & 0x0F);
HAL_EXIT_CRITICAL_SECTION(_sReg);
}
现在就卡在看门 狗这儿了,板子没有设计外部32.768KHz晶振,想用1s的看门狗,如何解决?能用250ms WatchDog的也好啊...求解!
请勿重复发帖,谢谢
这个问题一直没有解决,TI的文档也没有说明,所有与复位有关的都与WatchDog有关。
解决了,是OSC_32KHZ这个定义有问题,默认的定义是0.