cancel
Showing results for 
Search instead for 
Did you mean: 

What is the proper code for STM8S External Interrupt?

JKain.1
Associate

Being new to STM8 development, I'm having a problem getting the external interrupt to work. There are many bits and pieces of external interrupt code I've found on the internet, but I haven't found a definitive piece of code that works as expected. Here are the relevant details of my setup:

-STM8S105K

-STVD with Cosmic C

-External Interrupt (irq4) on PORTB PB2 and executes via a push button switch to GND.

-Standard Peripheral Library - using *_.itc.c, *_interrupt_vector.c, *_.exti.c, and all other

relevant source and header files.

Here's my problem:

While emulating with ST-LINK V2, when the push button is pressed the code vectors to the line extern @far @interrupt void EXTI1_PORTB_IRQHandler(void); as shown in the interrupt vector file below.

stm8_interrupt_vector.c

/*   BASIC INTERRUPT VECTOR TABLE FOR STM8 devices

 *   Copyright (c) 2007 STMicroelectronics*/

#include “stm8s_itc.h�?

typedef void @far (*interrupt_handler_t)(void);

struct interrupt_vector {

   unsigned char interrupt_instruction;

   interrupt_handler_t interrupt_handler;

};

//@far @interrupt void NonHandledInterrupt(void) {

   /* Set a breakpoint here */

//}

extern @far @interrupt void EXTI1_PORTB_IRQHandler(void);

extern void _stext();    

/* startup routine */

struct interrupt_vector const _vectab[] = {

   {0x82, (interrupt_handler_t)_stext}, /* reset */

   {0x82, NonHandledInterrupt}, /* trap */

   {0x82, NonHandledInterrupt}, /* irq0 */

   {0x82, NonHandledInterrupt}, /* irq1 */

   {0x82, NonHandledInterrupt}, /* irq2 */

   {0x82, NonHandledInterrupt}, /* irq3 */

   {0x82, EXTI1_PORTB_IRQHandler}, /* irq4 */

   {0x82, NonHandledInterrupt}, /* irq5 */

If I step through the code afterward, an IRET instruction (as shown in disassembly) takes it right back to main without executing the ISR. Should my code vector directly to the ISR when the push button is pressed? Should the ISR reside in the *_itc.c file, or in main.c? I've tried inserting my ISR in both places without success. Please Help!

Here is my very basic test ISR:

@far @interrupt void EXTI1_PORTB_IRQHandler(void)

{

   __asm ("nop");

}

0 REPLIES 0