Explanation
Most part of the code is same as previous codes and so I won’t be going through them again. However,
there’s something new:
void EXTI_setup(void)
{
ITC_DeInit();
ITC_SetSoftwarePriority(ITC_IRQ_PORTB, ITC_PRIORITYLEVEL_0);
EXTI_DeInit();
EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOB, EXTI_SENSITIVITY_FALL_ONLY);
EXTI_SetTLISensitivity(EXTI_TLISENSITIVITY_FALL_ONLY);
enableInterrupts();
}
This function is where we are setting up the external interrupt. The first two lines deinitiate the
interrupt controller and set priority while initiating it. It is not mandatory unless you want to set
interrupt priority. Then we configure the external interrupt on PORTB pins. We also set the edge that
will invoke an interrupt. Finally, we enable global interrupt. There goes the main.c file
Now it’s time to explain the stm8_interrupt_vector.c file. The top part of this file must include this
line #include "stm8s_it.h". It must also have the following section commented out:
//@far @interrupt void NonHandledInterrupt (void)
//{
/* in order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction
*/
// return;
//}
We need to let our compiler know the name of the function that it should call when a particular
interrupt is triggered. There are two parts for that. Firstly, the interrupt vector address and secondly
the name of the function. This is reason for this line:
{0x82, (interrupt_handler_t)EXTI1_IRQHandler}, /* irq4 */
Lastly, the stm8s_it.h and stm8s_it.c files contain the prototype and the function that will execute the
interrupt service routine (ISR). In our case, the ISR will change the logic state of the Boolean variable
state. This will alter that flashing rate in the main loop.
Demo
Video link: https://www.youtube.com/watch?v=P6qdmWgH-Ls