打印
[STM8]

STM8S103的LSI频率测量问题

[复制链接]
1419|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Jade_yu|  楼主 | 2015-11-9 23:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本人想用STM8S103的AWU功能,看了ST库函数的例程也模仿着写了一段LSI频率的测试代码,代码如下:
//**********************************************************
//LSI频率测量函数*******************************************
uint32_t LSIMeasurment(void)
{
  
  uint32_t lsi_freq_hz = 0;
  uint32_t fmaster = 0;
  unint ICValue1 = 0;
  unint ICValue2 = 0;
        unchar tmpccr1h = 0;
        unchar tmpccr1l = 0;       

  /* Get master frequency */
  fmaster = 16000000U;//16MHZ
  /* Enable the LSI measurement: LSI clock connected to timer Input Capture 1 */
  AWU_CSR |= 0x01;//AWU_CSR_MSR;

  /* Measure the LSI frequency with TIMER Input Capture 1 */  
  /* Capture only every 8 events!!! */
  /* Enable capture of TI1 */
      
  TIM1_CCER1 &= 0xFE;//bit0=0,禁止捕抓才能对TIM1_CCMR1的(CC1S位操作)
  TIM1_CCMR1 = 0xFD; // TIM1设为捕抓输入模式,IC1映射到TI1上,每8件事触发一次。
  TIM1_CCER1 &= 0xFD;//
  TIM1_CCER1 |= 0x01;//使能捕抓       
  /* Enable TIM1 */
        TIM1_CR1 |= 0x01;  //启动计数器//TIM1_Cmd(ENABLE);
  
  /* wait a capture on cc1 */
  while((TIM1_SR1 & 0x02) != 0x02) ;
  /* Get CCR1 value*/
  //ICValue1 = TIM1_GetCapture1();
        tmpccr1h = TIM1_CCR1H;
        tmpccr1l = TIM1_CCR1L;
        ICValue1 = (unint) tmpccr1l;
        ICValue1 |= (unint)((unint)tmpccr1h << 8);       
       
  TIM1_SR1 &= 0xFD;//CC1IF位清0//TIM1_ClearFlag(TIM1_FLAG_CC1);
  
  /* wait a capture on cc1 */
  while((TIM1_SR1 & 0x02) != 0x02);
  /* Get CCR1 value*/
  //ICValue2 = TIM1_GetCapture1();
        tmpccr1h = TIM1_CCR1H;
        tmpccr1l = TIM1_CCR1L;
        ICValue1 = (unint) tmpccr1l;
        ICValue1 |= (unint)((unint)tmpccr1h << 8);       
       
  TIM1_SR1 &= 0xFD;//CC1IF位清0//TIM1_ClearFlag(TIM1_FLAG_CC1);
  
  /* Disable IC1 input capture */
  TIM1_CCER1 &= 0XFE;//(uint8_t)(~TIM1_CCER1_CC1E);
  /* Disable timer2 */
  //TIM1_Cmd(DISABLE);
  TIM1_CR1 &= 0xFE;  //停止计数器//TIM1_Cmd(DISABLE);
  /* Compute LSI clock frequency */
  lsi_freq_hz = (8 * fmaster) / (ICValue2 - ICValue1);
  
  /* Disable the LSI measurement: LSI clock disconnected from timer Input Capture 1 */
  AWU_CSR &= 0xFE;

return (lsi_freq_hz);
}

现在的问题是一直没能正确测量LSI死循环在“  while((TIM1_SR1 & 0x02) != 0x02) ;”这里了,LSI频率已经打开了的。
请大家帮忙分析分析问题所在,谢谢!
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

1

帖子

0

粉丝