cancel
Showing results for 
Search instead for 
Did you mean: 

How to use GPIO external interrupts

asim1108
Associate II
Posted on June 24, 2011 at 07:31

Hi,

Port-c pc6 is connected to a 50 Hz square wave signal, the

problem is the variable cCounter did not increment in the

port_c_isr, so the PC4 pin did not toggle, please advise

about the solution.

Thanks

========================================================

#include <iostm8s903.h>

unsigned char       cCounter;

void    main(void)

{

 CLK_ICKCR = 0x01;      // high speed internal osc enable

 CLK_ECKCR = 0x00;      // high speed xtal osc disable

 CLK_SWR  = 0xE1;       // select high speed internal osc as master clock

 CLK_CKDIVR = 0x10;     // master clk divide / 4, cpu clk div / 1

 

 PC_ODR = 0x9E;

 PC_DDR = 0x9E;

 PC_CR1 = 0xFF;

 PC_CR2 = 0x40;         // pc6 interrupt enable

 EXTI_CR1 = 0x20;       // port-c interrupt falling edge only

 

                        // global interrupt enable

 _asm(''rim'');

 

 while (1)

  {

   while (cCounter < 25);

   PC_ODR |= 0x10;             // set PC4 pin

   cCounter = 0;

   

   while (cCounter < 25);

   PC_ODR &= ~0x10;            // clear PC4 pin

   cCounter = 0;   

  }

}

@far @interrupt void port_c_isr(void)

{

 cCounter++;

}

=====================================

stm8_interrupt_vector.c file contents

=====================================

/*    BASIC INTERRUPT VECTOR TABLE FOR STM8 devices

 *    Copyright (c) 2007 STMicroelectronics

 */

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

struct interrupt_vector

 {

  unsigned char     interrupt_instruction;

  interrupt_handler_t   interrupt_handler;

 };

@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;

}

extern @far @interrupt void port_c_isr(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, NonHandledInterrupt},                /* irq4  */

    {0x82, port_c_isr},                         /* irq5     port-c  exti */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

};

2 REPLIES 2
luca239955_stm1_st
Senior II
Posted on June 24, 2011 at 10:01

assuming that the interrupt is actually generated and serviced, the problem might come from the fact that your variable is not declared as volatile.

asim1108
Associate II
Posted on June 27, 2011 at 08:58

Thanks luca the problem is solved by using the volatile feature.

I have another question, how to check and clear the external interrupt status

if i do not want to use the gpio external interrupts?

Regards