2019-08-15 08:59 PM
The chip is stm8s103f3p6, and I wanna use lsi as clk and tim4 to make a timer, there are two strange things happened.
I have already set LSI_EN to enable, can anyone help find what happened?
Thx
the code:
unsigned long elapseTime = 0;
void DelayMS(unsigned int ms) {
unsigned long lmttime = elapseTime + ms;
while(lmttime >= elapseTime);
return;
}
int main( void )
{
CLK_DeInit();
CLK_LSICmd(ENABLE);
CLK_ClockSwitchConfig(CLK_SWITCHMODE_MANUAL, CLK_SOURCE_LSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
while(CLK_GetFlagStatus(CLK_FLAG_LSIRDY)==RESET);
CLK_ClockSwitchCmd(ENABLE);
while(CLK_GetSYSCLKSource() != CLK_SOURCE_LSI){
}
TIM4_DeInit();
TIM4_TimeBaseInit(TIM4_PRESCALER_4, 32);
TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
TIM4_SetCounter(0x00);
TIM4_Cmd(ENABLE);
GPIO_DeInit(GPIOB);
GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_OUT_OD_LOW_SLOW);
GPIO_WriteReverse(GPIOB, GPIO_PIN_5);
enableInterrupts();
while (1) {
DelayMS(2000);
GPIO_WriteReverse(GPIOB, GPIO_PIN_5);
}
return 0;
}
INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
{
elapseTime++;
TIM4_ClearITPendingBit(TIM4_IT_UPDATE);
}
2019-11-25 05:39 PM
Hello, I have the same problem. Managed to solve?