cancel
Showing results for 
Search instead for 
Did you mean: 

Setting up an interrupt.........

jjhopkotcha
Associate II
Posted on July 27, 2011 at 11:59

Hi there folks,

I am currently controlling an STM32F100 LQFP48 using a program I am editing on IAR workspace. There is a function embedded in my program which checks for an audio sample using a microphone every 90ms and to notify that my program is listening i wish to have a short but noticeable output. (ie, one that lasts longer than 90ms). 

I expect I could set up any of the GPIO's to trigger an interrupt but I am unsure on what code I would need to do that. 

Also any knowledge on how the priority of an interrupt is set would be greatly appreciated. 

Thanks

JohnH

#interrupt #stm32f100
5 REPLIES 5
rosarium
Associate II
Posted on July 27, 2011 at 12:07

It will be better if you once go through the ref manual of STM32. The NVIC part.

Following is an example piece of code to set priority.

void NVIC_Configuration(void)

{

 

NVIC_InitTypeDef NVIC_InitStructure;

 

 

/* Deinitializes the NVIC */

 

NVIC_DeInit();

 

#ifdef

 

VECT_TAB_RAM

 

 

/* Set the Vector Table base location at 0x20000000 */

 

NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);

#else

 

/* VECT_TAB_FLASH

 

*/

 

/* Set the Vector Table base location at 0x08000000 */

 

NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

  

#endif

 

 

/* 1 bit for pre-emption priority, 3 bits for subpriority */

 

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

 

 

 

/* Enable the EXTI1 Interrupt (Touch Interrupt) */

 

NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQChannel;

 

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

 

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

 

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

 

NVIC_Init(&NVIC_InitStructure);

 

}

ezyreach
Associate II
Posted on July 27, 2011 at 12:45

@hopkins

You can set a timer interrupt for every 10mS. Then declare a timer counter variable and increment the variable in the timer interrupt routine.

In the main routine check for the timer counter variable has reached 9? If so then stop the timer and clear the timer counter variable and do the neccessary functions and then enable the timer.

Why you want to use  a GPIO for triggering an interrupt?  As the timer interrupt is the easiest way to do.

jjhopkotcha
Associate II
Posted on July 27, 2011 at 14:51

Thanks shankar, I understand what you mean now having researched interrupts a little more on the web. 

I think the type of interrupt that I desire will be a software one, so that I can effectively call the interrupt somewhere in my code, the processor will then carry it out for me, before returning for the next bit of code. 

Do you understand why I need to use an interrupt? I am running a listening function which checks for a value every 90ms, and some of my responses to the heard value are lasting longer than 90ms so throwing off response functions. 

Thanks 

John

Posted on July 27, 2011 at 14:57

Do you understand why I need to use an interrupt?

Actually it sounds like you need to use a lightweight RTOS with tasks/threads, and events or semaphores, and permits multitasking.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 27, 2011 at 17:03

I think the type of interrupt that I desire will be a software one

PendSV perhaps?

http://users.ece.utexas.edu/~valvano/EE345MSp10/view05_threads.ppt

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..