2012-11-12 08:22 AM
I need that display that I put on my stm32f4 Discovery is updated every second, I thought to do so through an interrupt TIM, but I do not know how to configure to work as TIM clock! can you give me some suggestions or examples?
2012-11-12 08:35 AM
Just set up the time base (prescale/period), and enable the Update interrupt.
2012-11-14 07:10 AM
I have configured in the following way TIM4
//file stm32f4xx_it.c
void TIM4_IRQHandler(void){
TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
STM_EVAL_LEDToggle(LED6);
}
//file of configuration
void Tim_Clock_IT(void){
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
//Configure TIM4
TIM_TimeBaseStructure.TIM_Period =SystemCoreClock ;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM4, ENABLE);
/* Enable TIM4 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
and to understand if they actually worked well I put the code in the interrupt routin STM_EVAL_LEDToggle(LED6), but the LED 6 never turns off, and according to my calculations should flash on and off once per second!
what is wrong??
2012-11-14 08:09 AM
Unless TIM4 is 32-bit you need to compute/factor your period/prescale values to fit in 16-bit ranges.
2012-11-14 08:56 AM
// TOGGLETIM4 STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
}
/**************************************************************************************/
void TIM4_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = ((SystemCoreClock / 10000) / 2) - 1;
TIM_TimeBaseStructure.TIM_Prescaler = 10000 - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* TIM4 enable counter */
TIM_Cmd(TIM4, ENABLE);
TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
}
/**************************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable TIM4 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**************************************************************************************/
void TIM4_IRQHandler(void)
{
TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
STM_EVAL_LEDToggle(LED6);
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
NVIC_Configuration();
STM_EVAL_LEDInit(LED6);
STM_EVAL_LEDOn(LED6);
TIM4_Configuration();
while(1); // Don't want to exit
}
/**************************************************************************************/
2012-11-14 09:05 AM
thank you very much Clive! for all the help you have given me :D