STM 32 F 103 RTC使用


LSE Readyカード死
st-linkダウンロードを使用してボードに電力を供給すると、電力供給能力が不足し、外部LSEが常にreadyできないが、LSIは可能である.外部電源に電力を供給した後、LSEもロックできます.翌日テストして、また詰まって死んで、電源の給電の問題ではありませんて、LSEが起きないのではないかと疑って、板の上の結晶の振動は単片機から少し遠くて、現在電池を取り付けていないで、テストは電池の問題に従っていないのではありません.Time_Init関数に次の初期化を加えます.
#if 1
  /* Enable LSE */
  RCC_LSEConfig(RCC_LSE_ON);
  /* Wait till LSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {}

  /* Select LSE as RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
#else
	RCC_LSICmd(ENABLE);
	
  while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
  {}		
		
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
#endif

RTC_WaitForSynchroカード死
まず、標準ライブラリの例であるRTC_コンフィギュレーションの下の3行のコードを上に置くTime_Initでは、LSIを使用する場合はLSI初期化も出さなければなりませんが、バッテリーが取り付けられていないためかもしれません.こことTime_Init初期化が一部繰り返されたのはBKP_DeInitです.そうしないと異常になります.
/**
  * @brief  Configures the RTC.
  * @param  None
  * @retval None
  */
void RTC_Configuration(void)
{
#if 0 /*move to top for RTC_WaitForSynchro dead*/
   /* Enable PWR and BKP clocks */
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

   /* Allow access to BKP Domain */
   PWR_BackupAccessCmd(ENABLE);
#endif
  /* Reset Backup Domain */
  BKP_DeInit();
  
#if 1
#if EN_RTC_LSE
  /* Enable LSE */
  RCC_LSEConfig(RCC_LSE_ON);
  /* Wait till LSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {}

  /* Select LSE as RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
#else
  RCC_LSICmd(ENABLE);
	
  while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
  {}		
		
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
#endif
#endif
  /* Enable RTC Clock */
  RCC_RTCCLKCmd(ENABLE);

  /* Wait for RTC registers synchronization */
  RTC_WaitForSynchro();

  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();

  /* Enable the RTC Second */
  RTC_ITConfig(RTC_IT_SEC, ENABLE);

  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();

  /* Set RTC prescaler: set RTC period to 1sec */
  RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */

  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();

}

void Time_init(void)
{
	/*Enables the clock to Backup and power interface peripherals    */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP | RCC_APB1Periph_PWR,ENABLE);
	/*Allow access to Backup Registers*/
  PWR_BackupAccessCmd(ENABLE);
  
#if EN_RTC_LSE
  /* Enable LSE */
  RCC_LSEConfig(RCC_LSE_ON);
  /* Wait till LSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {}

  /* Select LSE as RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
#else
  RCC_LSICmd(ENABLE);
	
  while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
  {}		
		
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
#endif
    
	/*delay_us(100);*//*delay because uart print error chars*/
	/*uart_printf("%s line%d\r
", __FUNCTION__, __LINE__);*/
if (BKP_ReadBackupRegister(BKP_DR1) != CONFIGURATION_DONE) { /* Backup data register value is not correct or not yet programmed (when the first time the program is executed) */ /* RTC Configuration */ uart_printf("RTC configured....\r
"
); RTC_Configuration(); uart_printf("Please Set time and date from shell\r
"
); BKP_WriteBackupRegister(BKP_DR1, CONFIGURATION_DONE); } else { delay_us(2000); /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { uart_printf("Power On Reset occurred...."); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { uart_printf("External Reset occurred...."); } uart_printf("No need to configure RTC....\r
"
); /* Wait for RTC registers synchronization */ RTC_WaitForSynchro(); /* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } /* Clear reset flags */ RCC_ClearFlag(); /* Check if how many days are elapsed in power down/Low Power Mode- Updates Date that many Times*/ CheckForDaysElapsed(); s_time_date.Month = BKP_ReadBackupRegister(BKP_DR2); s_time_date.Day = BKP_ReadBackupRegister(BKP_DR3); s_time_date.Year = BKP_ReadBackupRegister(BKP_DR4); }

しかし、私の問題は解決されていません.回路が何らかの異常状態に入ったのではないかと疑っています.バックアップバッテリーは置いていませんが、RTCが構成されていることを常に検出しています.CONFIGURATION_を変更します.DONEの値は、RTCを再構成させた後、バグを解除!!!