why interrup occerd when TIM1 is not ENABLE??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-25 1:19 AM
hi guys.
i wrote a code with IAR , and when is run the code in stm32f103ret , cpu go to the interrupt s routin.
i dont know why??!!i want to have 1msecond delay for each timer priode , but i cant do that. when the code runs , cpu go to interrupt routine fanction. i do some thing that i know. but i cant do this activity. this is my code:who know why I cant??
so thanks.#include 'stm32f10x.h'
#include 'stm32f10x_gpio.h' // for Enable LCD#include 'stm32f10x_rcc.h' //for Enable LCD#include 'stm32f10x_tim.h'#include 'LCDLib.h'#include 'delay.h'void tim_init(void);void GPIO_init(void);void TIM1_UP_TIM16_IRQHandler (void){ int i; i = TIM_GetPrescaler(TIM1); lcdGoxy(1 , 2); lcdPutInt(i); lcdGoxy(1 , 3); lcdPutString ('tim activated'); TIM_ClearITPendingBit(TIM1,TIM_IT_Update);}int main(){ lcd_init(); tim_init(); GPIO_init(); while(1){ } }void tim_init(){ RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 55000; TIM_TimeBaseStructure.TIM_Prescaler = 55999; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE); NVIC_InitTypeDef NVIC_InitStructure; /* Enable the TIM2 global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);}void GPIO_init(void){ RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOA, ENABLE ); GPIO_InitTypeDef gpioA; gpioA.GPIO_Mode = GPIO_Mode_Out_PP ; gpioA.GPIO_Pin = GPIO_Pin_0; gpioA.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init ( GPIOA, &gpioA ); }Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-27 2:05 PM
&sharpinclude 'stm32f10x.h'
&sharpinclude 'stm32f10x_gpio.h' // for Enable LCD&sharpinclude 'stm32f10x_rcc.h' //for Enable LCD&sharpinclude 'stm32f10x_tim.h'&sharpinclude 'LCDLib.h'&sharpinclude 'delay.h'void tim_init(void);void GPIO_init(void);void TIM1_UP_IRQHandler(void) // assuming startup_stm32f103xe.s pulled
{ static int i = 0;if (TIM_GetITStatus(TIM1, TIM_IT_Update) == SET)
{ TIM_ClearITPendingBit(TIM1,TIM_IT_Update);GPIOA->ODR ^= GPIO_Pin_0; // Toggle PA0
lcdGoxy(1 , 2);
lcdPutInt(i++); // Incrementing countlcdGoxy(1 , 3);
lcdPutString ('tim activated'); }}void TIM1_UP_TIM16_IRQHandler(void) // if startup_stm32f10x_hd_vl.s being pulled
{ TIM1_UP_IRQHandler();}int main(){ RCC_ClocksTypeDef RCC_Clocks; uint32_t j;lcd_init();
lcdPutString ('Believe Your Dreams.');tim_init();
GPIO_init();RCC_GetClocksFreq(&RCC_Clocks);
j = (RCC_Clocks.PCLK2_Frequency/1000);
lcdGoxy(1 , 4);
lcdPutInt(j);GPIO_WriteBit(GPIOA, GPIO_Pin_0, Bit_SET);
while(1){
}
}void tim_init()
{ NVIC_InitTypeDef NVIC_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
/* Enable the TIM1 global Interrupt, before we enable it on TIM */
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 36000 - 1; // KHz, take 36 MHz clock to 1 KHz TIM_TimeBaseStructure.TIM_Period = 1000 - 1; // Hz (1) 1000 ticks of 1 KHz clock TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);/* TIM1 enable counter */
TIM_Cmd(TIM1, ENABLE);/* Enable the update interrupt */
TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);}void GPIO_init(void)
{ GPIO_InitTypeDef gpioA;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
gpioA.GPIO_Mode = GPIO_Mode_Out_PP;
gpioA.GPIO_Pin = GPIO_Pin_0; gpioA.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init (GPIOA, &gpioA);}Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-25 7:33 AM
TIM1_UP_IRQn not equivalent to TIM1_UP_TIM16_IRQHandler, needs some coherency.
Check the name in the vector table in startup_stm32f1xxx.s if there is no linkage, the function isn't going to get called.
If using .CPP files, makes sure to use extern 'C' so the names aren't mangled.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-27 7:11 AM
thanks.
i change to tim2 . and i change startup file (got it from cube).but cant slove my problem.i test many ways,i dont know what do i do !!!!
do you have any seggestions for me??thanks you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-27 7:30 AM
You test many ways but show next to no detail. What file? What are the vectors in it? Consider ZIPing up a project and attaching so the context can be understood.
The sample shown looks to come from SPL rather than Cube/HAL
The TIM divides down 36 MHz, it will interrupt every 85 seconds, not 1 ms
TIM1_UP_IRQHandler would be expected with
TIM1_UP_IRQn
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-27 1:09 PM
thanks.
i just want to have delay from timer counter of stm32. i mean when the counter overflows , then i have an interrupt and in function of interrupt i do somethings.
i wrote code but i dont know when i init the timer/counter , interrupt happened and cpu do the interrupt routin code with no delay.
i havent any delay with timer/counter.
i saw a lot of example and the code was same but the code of mine dosent work.
i use stm32f103ret and IAR.
this is my project file :
so thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-27 2:05 PM
&sharpinclude 'stm32f10x.h'
&sharpinclude 'stm32f10x_gpio.h' // for Enable LCD&sharpinclude 'stm32f10x_rcc.h' //for Enable LCD&sharpinclude 'stm32f10x_tim.h'&sharpinclude 'LCDLib.h'&sharpinclude 'delay.h'void tim_init(void);void GPIO_init(void);void TIM1_UP_IRQHandler(void) // assuming startup_stm32f103xe.s pulled
{ static int i = 0;if (TIM_GetITStatus(TIM1, TIM_IT_Update) == SET)
{ TIM_ClearITPendingBit(TIM1,TIM_IT_Update);GPIOA->ODR ^= GPIO_Pin_0; // Toggle PA0
lcdGoxy(1 , 2);
lcdPutInt(i++); // Incrementing countlcdGoxy(1 , 3);
lcdPutString ('tim activated'); }}void TIM1_UP_TIM16_IRQHandler(void) // if startup_stm32f10x_hd_vl.s being pulled
{ TIM1_UP_IRQHandler();}int main(){ RCC_ClocksTypeDef RCC_Clocks; uint32_t j;lcd_init();
lcdPutString ('Believe Your Dreams.');tim_init();
GPIO_init();RCC_GetClocksFreq(&RCC_Clocks);
j = (RCC_Clocks.PCLK2_Frequency/1000);
lcdGoxy(1 , 4);
lcdPutInt(j);GPIO_WriteBit(GPIOA, GPIO_Pin_0, Bit_SET);
while(1){
}
}void tim_init()
{ NVIC_InitTypeDef NVIC_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
/* Enable the TIM1 global Interrupt, before we enable it on TIM */
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 36000 - 1; // KHz, take 36 MHz clock to 1 KHz TIM_TimeBaseStructure.TIM_Period = 1000 - 1; // Hz (1) 1000 ticks of 1 KHz clock TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);/* TIM1 enable counter */
TIM_Cmd(TIM1, ENABLE);/* Enable the update interrupt */
TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);}void GPIO_init(void)
{ GPIO_InitTypeDef gpioA;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
gpioA.GPIO_Mode = GPIO_Mode_Out_PP;
gpioA.GPIO_Pin = GPIO_Pin_0; gpioA.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init (GPIOA, &gpioA);}Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-28 3:33 AM
i am realy thank you.
you help me a lot.thanks.
