打印

STM32 RTC

[复制链接]
2549|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hisenseITS|  楼主 | 2009-4-22 14:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
void RTC_Configuration(void)
{
  u32 delay; 
   /* Enable PWR and BKP clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Allow access to BKP Domain */
  PWR_BackupAccessCmd(ENABLE);

  /* Reset Backup Domain */
  BKP_DeInit();

 do 
  { 
       //delay about 0.1ms  
      for(delay = 0;delay < 5000;delay++); 
       // Enable HSE 
     RCC_LSEConfig(RCC_LSE_ON); 
  }
  while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);  
  // Select HSE as RTC Clock Source
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);  

  /* Enable RTC Clock */
  RCC_RTCCLKCmd(ENABLE);

#ifdef RTCClockOutput_Enable  
  /* Disable the Tamper Pin */
  BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
                               functionality must be disabled */
                               
  /* Enable RTC Clock Output on Tamper Pin */
  BKP_RTCCalibrationClockOutputCmd(ENABLE);
#endif 

  /* 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) */
  //RTC_SetPrescaler(62499); /* RTC period = RTCCLK/RTC_PR = (8M/128=62.5kHz)/(62499+1) */
    
  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
  
  /* To output second signal on Tamper pin, the tamper functionality
       must be disabled (by default this functionality is disabled) */
  BKP_TamperPinCmd(DISABLE);

  /* Enable the RTC Second Output on Tamper Pin */
  BKP_RTCOutputConfig(BKP_RTCOutputSource_Second);
  
}

仅仅修改使用外部低速晶振后,CPU状态指示灯的关启周期由2秒变为8.4秒,请问为什么?
沙发
ST_ARM| | 2009-4-22 14:42 | 只看该作者

修改后

/********************************************************************
* Function Name  : RCC_Configuration
* Description    : Configures the different system clocks.
* Input          : None
* Output         : None
* Return         : None
********************************************************************/
void RCC_Configuration(void)
{
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if (HSEStartUpStatus == SUCCESS) {
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);

    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);

    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

    /* Enable PLL */
    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {}

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */
    while (RCC_GetSYSCLKSource() != 0x08)
    {}
  }
}
/********************************************************************
* Function Name  : RTC_Configuration
* Description    : Configures the RTC.
* Input          : None
* Output         : None
* Return         : None
********************************************************************/
void RTC_Configuration(void)
{
    u32 delay; 
    /* Enable PWR and BKP clocks */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

    /* Allow access to BKP Domain */
    PWR_BackupAccessCmd(ENABLE);

    /* Reset Backup Domain */
    BKP_DeInit();

    // Select HSE/128 as RTC Clock Source
    RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div128);  

    /* 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(62499); /* RTC period = RTCCLK/RTC_PR = (8M/128=62.5kHz)/(62499+1) */
    
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
  
    /* To output second signal on Tamper pin, the tamper functionality
        must be disabled (by default this functionality is disabled) */
    BKP_TamperPinCmd(DISABLE);

    /* Enable the RTC Second Output on Tamper Pin */
    BKP_RTCOutputConfig(BKP_RTCOutputSource_Second);

#ifdef RTCClockOutput_Enable  
    /* Disable the Tamper Pin */
    BKP_TamperPinCmd(DISABLE);    /* To output RTCCLK/64 on Tamper pin, the tamper
                                functionality must be disabled */
    /* Enable RTC Clock Output on Tamper Pin */
    BKP_RTCCalibrationClockOutputCmd(ENABLE);
#endif 
}

使用特权

评论回复
板凳
highend| | 2009-4-22 14:48 | 只看该作者

哪家公司的6pF晶振?

.

使用特权

评论回复
地板
ST_ARM| | 2009-4-22 14:57 | 只看该作者

3楼的

本帖是为大客户专门贴出的,为他们修改代码,与晶振无关,客户的系统运行已经正常,只是时钟源设置不正确。

使用特权

评论回复
5
ST_ARM| | 2009-4-22 15:30 | 只看该作者

这是我使用RTC产生1s中断的例程

时钟源使用的是:HSE/128。
相关链接:https://bbs.21ic.com/upfiles/img/20094/2009422152718171.zip

使用特权

评论回复
6
香水城| | 2009-4-22 17:09 | 只看该作者

你的外部晶振频率是多少?

转用外部低速晶振之前,RTC的时钟是什么?频率多少?

使用特权

评论回复
7
香水城| | 2009-4-23 17:56 | 只看该作者

楼主不见了?

按照你提供的电话打过去,但没有人接。

出差了???

使用特权

评论回复
8
ST_ARM| | 2009-4-23 20:46 | 只看该作者

我所附的代码就是他们想要的

问题已经解决。

使用特权

评论回复
9
hugo0chen| | 2014-2-18 17:50 | 只看该作者
这样看来使用HSE/128的效果会比外部LSE=32768的效果理想l咯?

使用特权

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

本版积分规则

1

主题

1

帖子

0

粉丝