2010-10-20 02:55 AM
Timer interrupt
2011-05-17 05:11 AM
2011-05-17 05:11 AM
Hi ANN,
I have some bits using TIM1 on a ST..103.. that may help. These use the standard libraries.
Put this somewhere in your main.
NVIC_InitTypeDef NVIC_InitStructure;
TIM1_TimeBaseInitTypeDef TIM1_TimeBaseInitStruct;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_TIM1, ENABLE);
// Set timer1
TIM1_TimeBaseInitStruct.TIM1_Prescaler = 8;
TIM1_TimeBaseInitStruct.TIM1_CounterMode = TIM1_CounterMode_Up;
TIM1_TimeBaseInitStruct.TIM1_Period = 10000;
TIM1_TimeBaseInitStruct.TIM1_ClockDivision = TIM1_CKD_DIV1;
TIM1_TimeBaseInitStruct.TIM1_RepetitionCounter = 0;
TIM1_TimeBaseInit (&TIM1_TimeBaseInitStruct);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 9;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init (&NVIC_InitStructure);
TIM1_ClearITPendingBit (TIM1_FLAG_Update); // Clear Interrupt
TIM1_ITConfig (TIM1_FLAG_Update, ENABLE); // Enable Interrupt
TIM1_Cmd (ENABLE); // Enable Timer
This next bit assumes a static variable called led_timer initialised to 0, that your LED is on port b and GPIO_LED is defined as the pin your LED is on.
Find TIM1_UP_IRQHandler() in stm32f10x_it.c and put the following code there :-
void TIM1_UP_IRQHandler(void)
{
TIM1_ClearITPendingBit (TIM1_FLAG_Update);
led_timer=1-led_timer;
if (led_timer)
GPIO_ResetBits (GPIOB, GPIO_LED);
else
GPIO_SetBits (GPIOB, GPIO_LED);
}
That should get you a timer interrupt ticking. Play with the Period and Prescaler to get it running at the right speed.
Sorry if it's a bit of a hack, I've taken it from bits of code I have and tied it together. Hopefully it will be enough to get you going.Cheers,
2011-05-17 05:11 AM
Hi ANN
Could you please let me know where you got your STM32L152 devices or board from. I do not seem to find any distributor here in the US for teh low power family. Thanks stmdesi2011-05-17 05:11 AM
Hi ANN,
I have looked for the site dedicated to STM32L family and I diidn't find eval board documentation neither ST library. I have found only reference manual ,datasheet and 2 application notes. Perhaps STM32L152-EVAL isn't from ST. could you trell us where to find it in Germany ? Thanks ANN, Herzlich, MCU Lüfter