打印
[STM32F2]

关于RTC及PC13的问题

[复制链接]
2724|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
水工鸟|  楼主 | 2014-2-17 11:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
目前在用207做项目,使用RTC及BKP RAM,因为不用tamper功能,再加上IO不是太够,就拿PC13顶数做模拟量的通道切换,禁用了PC13的tamper功能。现在问题出来了:在上电的时候有时会出现RTC清零的情况;当配置不变但是不进行切换动作(即PC13的状态不变)的时候,则不会出现RTC清零。从数据手册上看,PC13是可以作为IO用的,这样我就搞不明白问题所在了,请香版及各位有经验的大侠们给支招,多谢了!
沙发
水工鸟|  楼主 | 2014-2-17 11:27 | 只看该作者
void RTC_Config(void)
{
  /* Enable the PWR clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Allow access to RTC */
  PWR_BackupAccessCmd(ENABLE);
   
#if defined (RTC_CLOCK_SOURCE_LSI)  /* LSI used as RTC source clock*/
/* The RTC Clock may varies due to LSI frequency dispersion. */   
  /* Enable the LSI OSC */
  RCC_LSICmd(ENABLE);

  /* Wait till LSI is ready */  
  while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
  {
  }

  /* Select the RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
  
  SynchPrediv = 0xFF;
  AsynchPrediv = 0x7F;

#elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */
  /* 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);
  
  SynchPrediv = 0xFF;
  AsynchPrediv = 0x7F;

#else
  #error Please select the RTC Clock source inside the main.c file
#endif /* RTC_CLOCK_SOURCE_LSI */
  
  /* Enable the RTC Clock */
  RCC_RTCCLKCmd(ENABLE);
  
  /* Wait for RTC APB registers synchronisation */
  RTC_WaitForSynchro();
}


void RTC_init(void)
{
        RTC_InitTypeDef RTC_InitStructure;
        TFT_Show4Hex(300, 200, RTC->BKP0R, 16, 0);
        TFT_Show4Hex(300, 220, RTC->BKP19R, 16, 0);
        //if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2)
        if(RTC->BKP0R != 0x32F2 && RTC->BKP19R != 0x32F2)
        {  
                /* RTC configuration  */
                RTC_Config();
                RTC_TamperCmd(RTC_Tamper_1, DISABLE);
                /* Configure the RTC data register and RTC prescaler */
                RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv;
                RTC_InitStructure.RTC_SynchPrediv = SynchPrediv;
                RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
               
                /* Check on RTC init */
                if (RTC_Init(&RTC_InitStructure) == ERROR)
                {
                  TFT_ShowString(0,176,(uint8_t*)"***** RTC Prescaler Config failed ********");
                }
               
                /* Configure the time register */
                RTC_TimeRegulate(0x12,0x12,0x12,0x03,0,0,0);
                PWR_BackupAccessCmd(DISABLE);
        }
        else
        {
                /* Check if the Power On Reset flag is set */
                if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
                {
                  TFT_ShowString(0,196,(uint8_t*)"Power On Reset occurred....");
                }
                /* Check if the Pin Reset flag is set */
                else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
                {
                  TFT_ShowString(0,196,(uint8_t*)"External Reset occurred....");
                }
               
                TFT_ShowString(0,196,(uint8_t*)"No need to configure RTC....");
               
                /* Enable the PWR clock */
                RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
               
                /* Allow access to RTC */
                PWR_BackupAccessCmd(ENABLE);
               
                /* Wait for RTC APB registers synchronisation */
                RTC_WaitForSynchro();
                RTC_TamperCmd(RTC_Tamper_1, DISABLE);
                PWR_BackupAccessCmd(DISABLE);
                RTC_TimeShow(600, 36);
                RTC_DateShow(600, 16);
        }
}

使用特权

评论回复
板凳
水工鸟|  楼主 | 2014-2-18 12:05 | 只看该作者
@香水城  试验了很多方式还是搞不定这个问题,是否当使用RTC功能的时候PC13不能作为IO口用?请版主指导一下,谢谢!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:70后老电工

18

主题

230

帖子

1

粉丝