CPU采用了STM32L151C8T6,外接32768Hz晶体LSE, 和8Mhz的HSE,HSE作为时钟工作正常,现在想使用硬件RTC,参考STM32L1xx_StdPeriph_Lib_V1.3.1的例子中提供的初始化代码,运行时却不正常,代码如下:
void RCC_Configuration(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC Domain */
PWR_RTCAccessCmd(ENABLE);
/* Check if the StandBy flag is set */
if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
{
/* Clear StandBy flag */
PWR_ClearFlag(PWR_FLAG_SB);
/* Turn on LED2 */
//STM_EVAL_LEDOn(LED2);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* No need to configure the RTC as the RTC config(clock source, enable,
prescaler,...) are kept after wake-up from STANDBY */
}
else
{
/* RTC Configuration ******************************************************/
/* Reset RTC Domain */
RCC_RTCResetCmd(ENABLE);
RCC_RTCResetCmd(DISABLE);
/* Enable the LSE OSC */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Set the RTC time base to 1s */
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
RTC_InitStructure.RTC_SynchPrediv = 0x00FF;
RTC_Init(&RTC_InitStructure);
/* Set the time to 01h 00mn 00s AM */
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
RTC_TimeStructure.RTC_Hours = 0x01;
RTC_TimeStructure.RTC_Minutes = 0x00;
RTC_TimeStructure.RTC_Seconds = 0x00;
RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
}
/* Clear RTC Alarm A flag */
RTC_ClearFlag(RTC_FLAG_ALRAF);
}
void SysTickConfig(void)
{
/* SysTick interrupt each 250 ms with SysTick Clock equal to 4MHz */
if (SysTick_Config((SystemCoreClock/8) / 4))
{
/* Capture error */
while (1);
}
/* Select AHB clock(HCLK) divided by 8 as SysTick clock source */
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
/* Set SysTick Preemption Priority to 1 */
NVIC_SetPriority(SysTick_IRQn, 0x04);
}
int main(void)
{
RCC_Configuration();
PWR_WakeUpPinCmd(PWR_WakeUpPin_1, ENABLE);
/* Configure the SysTick to generate an interrupt each 250 ms */
SysTickConfig();
while (1)
{
}
}
程序运行死在了RCC_Configuration,断点跟踪发现死在 while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) 中,这是为何,仔细检查外围电路没发现异常,不知道哪位遇到过同样问题,是如何解决的?
|