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 configura
tion -----------------------------------------*/
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);
}