你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM8L101 AWU应用LSI校准

[复制链接]
红外线11 提问时间:2018-12-18 11:29 /
Hi 各路大神,
STM8L101 内部38K LSI校准不起作用吗? 实测加不加LSIMeasurment(),定时1S ,抓出来的时间都一样。下面是官方代码稍加修改的。

INTERRUPT_HANDLER(AWU_IRQHandler,4)
{
  /* Clear AWU peripheral pending bit */
  AWU_GetFlagStatus();
  GPIO_ToggleBits(GPIOD, GPIO_Pin_0);//翻转
}


void main(void)
{

  /* Clock configuration -----------------------------------------*/
  CLK_Config();

  GPIO_Init(GPIOD,GPIO_Pin_0,GPIO_Mode_Out_PP_Low_Slow);
  /*AWU configuration --------------------------------------------*/
  AWU_Config();

  /* Enable general interrupts */
  enableInterrupts();   

  while (1)
  {
      halt(); /* Program halted */
  }
}


static void AWU_Config(void)
{
  /* Initialization of AWU */
   /* LSI calibration for accurate auto wake up time base*/

  AWU_LSICalibrationConfig(LSIMeasurment());
//  AWU_LSICalibrationConfig(10000);

  /* The delay corresponds to the time we will stay in Halt mode */
  AWU_Init(AWU_Timebase_1s);
}

uint32_t LSIMeasurment(void)
{

  uint32_t lsi_freq_hz = 0x0;
  uint32_t fmaster = 0x0;
  uint16_t ICValue1 = 0x0;
  uint16_t ICValue2 = 0x0;

  /* Get master frequency */
  fmaster = CLK_GetClockFreq();

  /* Enable the LSI measurement: LSI clock connected to timer Input Capture 1 */
  AWU->CSR |= AWU_CSR_MSR;

  /* Capture only every 8 events!!! */
  TIM2_ICInit(  TIM2_Channel_1, TIM2_ICPolarity_Rising, TIM2_ICSelection_DirectTI, TIM2_ICPSC_Div8, 0x0);

  /* Enable TIM2 */
  TIM2_Cmd(ENABLE);

  /* wait a capture on cc1 */
  while ((TIM2->SR1 & (uint8_t)TIM2_FLAG_CC1) != TIM2_FLAG_CC1);
  /* Get CCR1 value*/
  ICValue1 = TIM2_GetCapture1();
  TIM2_ClearFlag(TIM2_FLAG_CC1);

  /* wait a capture on cc1 */
  while ((TIM2->SR1 & (uint8_t)TIM2_FLAG_CC1) != TIM2_FLAG_CC1);
  /* Get CCR1 value*/
  ICValue2 = TIM2_GetCapture1();
  TIM2_ClearFlag(TIM2_FLAG_CC1);

  /* Disable IC1 input capture */
  TIM2->CCER1 &= (uint8_t)(~TIM_CCER1_CC1E);
  /* Disable TIM2 */
  TIM2_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 &= (uint8_t)(~AWU_CSR_MSR);

  return (lsi_freq_hz);

}

1545103709(1).jpg

收藏 评论2 发布时间:2018-12-18 11:29

举报

2个回答
sasalww 回答时间:2018-12-18 13:26:43

点评

不要在求助帖下回复无关话题  发表于 2018-12-19 17:14
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版