STM8S Interrupts With the STD Peripheral Library
So you have just purchased that wonderful sensor and now need it to grab the attention of the STM8S – enter the interrupt. In this post I will run through how to set up a GPIO port to have an incoming logic signal generate an interrupt.
As in previous posts on the STM8S, this post will use the IAR development environment and the STD Peripheral Library from ST.
Configuring the Port
The first step is to configure a port for input. The following code configures a pin on GPIOB for input:
GPIO_DeInit(GPIOB); GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_IN_FL_IT);
the next thing we need to do is to tell the system that this pin is allowed to generate an interrupt:
EXTI_SetExtIntSensitivity(GPIOB, EXTI_SENSITIVITY_RISE_ONLY);
So that should be all that’s required to configure the system to accept interrupts. Now we just need to process them.
Interrupt Handler
If you have followed my previous posts you will know that we need to copy some standard files across in order to access the STD Peripheral Library. One of the files we add to the project is stm8s_it.c. This holds the interrupt table for the chip. Scroll through the file and you will eventually reach some code which looks like this:
INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler, 4) { /* In order to detect unexpected events during development, it is recommended to set a breakpoint on the following instruction. */ }
Just place the code to be executed in this method. Remember, interrupt handlers should be small and concise.
Modules
This post requires that you add the code files for the following STD Peripheral Library modules:
- stm8s_gpio.c
- stm8s_exti.c
Conclusion
A relatively short post but there’s not much too it. I have successfully used this code to generate an interrupt from a sensor which generates a square wave of up to 500 KHz. The conditions I was using it in gave a maximum frequency of 20 KHz.
Tags: Electronics, Software Development, STM8
Saturday, May 12th, 2012 at 8:11 pm • Electronics, Software Development, STM8 • RSS 2.0 feed Both comments and pings are currently closed.