Tutorial: User Interrupts with Processor Expert
Join the DZone community and get the full member experience.
Join For Freei have been asked this question several times:
“how can i define my own interrupt vector with processor expert?”
so i think it deserves a short tutorial, if more than one person is asking this.
interrupts in processor expert: vectors.c
if you are using an interrupt device (spi, i2c, usb, etc), then processor expert cares about it. processor expert maintains the vector table but if i want to hook into an interrupt vector myself, i need to tell processor expert that. the interrupt vector table is generated as ‘vectors.c’ in the generated_code folder.
i’m using in this post screenshots from the newly released processor expert v10.4 version, but things apply to earlier versions too. i’m using here an arm project (kinetis kl02z), but things are pretty the same for any other architecture supported by processor expert. additionally, i’m *not* using the kinetis sdk here, as the way how the sdk deals with interrupts is a different thing, and only would apply to kinetis.interruptvector component
there is a component in the components library where i can hook my interrupt into the vector table:
that component does nothing else than let me overwrite the interrupt vector in the vector table. so if i add that component, i can configure it to use my interrupt routine. for example if i want to map the interrupts on port b to my handler, i only need to specify the interrupt and my function name:
then i only need to add that interrupt handler (myirq() in my example) and that’s it.
oh, wait: how to define other properties for that interrupt? i mean i usually can configure to create an interrupt on portb pin 7 on a falling edge, etc?
the answer is: either i configure all these settings in my code (setting the ‘trigger on’ flags, …), or i use a different component: the init_gpio one.
init_gpio component
if i want to configure a pin to create an interrupt on a specific event, i can use the init_gpio component found in the components library:
once i have added this component to my project, i specify the port and pin to be enabled and initialized:
:idea: here i can configure other properties like direction and pull resistor of the pin.
to enable the interrupt and to give my user interrupt function name, i do this in the ‘interrupts’ section:
interrupt code
what is missing is now my interrupt function in my application. an (empty) example would be like this:
void myirq(void) { /* my interrupt code here */ }
summary
processor expert takes care about the interrupt vectors and vector table. to define my own interrupts, i can use the interruptvector component which allows me to add my function name to the vector table. if i want to use interrupts with general purpose i/o pins and want to configure properties like pull-resistors, then the preferred way is to use the init_gpio component.
happy vectoring!Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
How To Use Pandas and Matplotlib To Perform EDA In Python
-
How To Scan and Validate Image Uploads in Java
-
Designing a New Framework for Ephemeral Resources
-
AI Technology Is Drastically Disrupting the Background Screening Industry
Comments