cancel
Showing results for 
Search instead for 
Did you mean: 

STM8L Discovery basic GPIO Interrupt

flol2204
Associate
Posted on February 11, 2015 at 19:38

Hey,

I've buyed the STM8L-Discovery board because it seems to be interesting. I've started reading manual and want to build an simple application: a string is be displayed on the lcd and I want to switch on the blue LED on PC7 in an ISR when pressing user button B2 on PC1, but I am be blockheaded, it won't work... So what I must change to make this simple application working:

---- main .c ------
#
include
''stm8l15x.h''
#
include
''stm8l15x_it.h''
main()
{
LCD_GLASS_Init();
GPIO_DeInit(GPIOC);
GPIO_Init(GPIOC, GPIO_Pin_1, GPIO_Mode_In_FL_IT);
GPIO_Init(GPIOC, GPIO_Pin_7, GPIO_Mode_Out_PP_Low_Slow);
enableInterrupts();
while
(1)
{
LCD_GLASS_ScrollSentence(
''A String''
,1,100); 
}
}
---- stm8l15x_it.h -----
#
include
''stm8l15x_gpio.h''
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_IT_H
#define __STM8L15x_IT_H
/* Includes ------------------------------------------------------------------*/
#
include
''stm8l15x.h''
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
#ifdef _COSMIC_
void _stext(void);
@far @interrupt void NonHandledInterrupt(void);
INTERRUPT void TRAP_IRQHandler(void); 
/* TRAP */
INTERRUPT void FLASH_IRQHandler(void); 
/* FLASH EOP/PG_DIS */
INTERRUPT void DMA1_CHANNEL0_1_IRQHandler(void); 
/* DMA1 Channel0/1*/
INTERRUPT void DMA1_CHANNEL2_3_IRQHandler(void); 
/*DMA1 Channel2/3*/
INTERRUPT void RTC_CSSLSE_IRQHandler(void); 
/* RTC /CSS_LSE */
INTERRUPT void EXTIE_F_PVD_IRQHandler(void); 
/*EXTI PORTE/EXTI PORTF/PVD*/
INTERRUPT void EXTIB_G_IRQHandler(void); 
/* EXTI PORTB / EXTI PORTG */
INTERRUPT void EXTID_H_IRQHandler(void); 
/* EXTI PORTD / EXTI PORTH*/
INTERRUPT void EXTI0_IRQHandler(void); 
/* EXTI PIN0 */
INTERRUPT void EXTI1_IRQHandler(void); 
/* EXTI PIN1 */
INTERRUPT void EXTI2_IRQHandler(void); 
/* EXTI PIN2 */
INTERRUPT void EXTI3_IRQHandler(void); 
/* EXTI PIN3 */
INTERRUPT void EXTI4_IRQHandler(void); 
/* EXTI PIN4 */
INTERRUPT void EXTI5_IRQHandler(void); 
/* EXTI PIN5 */
INTERRUPT void EXTI6_IRQHandler(void); 
/* EXTI PIN6 */
INTERRUPT void EXTI7_IRQHandler(void); 
/* EXTI PIN7 */
INTERRUPT void LCD_AES_IRQHandler(void); 
/* LCD /AES */
INTERRUPT void SWITCH_CSS_BREAK_DAC_IRQHandler(void); 
/* Switch CLK/CSS/TIM1 Break/DAC */
INTERRUPT void ADC1_COMP_IRQHandler(void); 
/*ADC1/COMP*/
INTERRUPT void TIM2_UPD_OVF_TRG_BRK_USART2_TX_IRQHandler(void); 
/* TIM2 UPD/OVF/TRG/BRK / USART2 TX */
INTERRUPT void TIM2_CC_USART2_RX_IRQHandler(void); 
/* TIM2 CAP / USART2 RX */
INTERRUPT void TIM3_UPD_OVF_TRG_BRK_USART3_TX_IRQHandler(void); 
/* TIM3 UPD/OVF/TRG/BRK /USART3 TX*/
INTERRUPT void TIM3_CC_USART3_RX_IRQHandler(void); 
/* TIM3 CAP/ USART3 RX */
INTERRUPT void TIM1_UPD_OVF_TRG_COM_IRQHandler(void);
/* TIM1 UPD/OVF/TRG/COM */
INTERRUPT void TIM1_CC_IRQHandler(void);
/* TIM1 CAP*/
INTERRUPT void TIM4_UPD_OVF_TRG_IRQHandler(void); 
/* TIM4 UPD/OVF/TRI */
INTERRUPT void SPI1_IRQHandler(void); 
/* SPI1 */
INTERRUPT void USART1_TX_TIM5_UPD_OVF_TRG_BRK_IRQHandler(void); 
/* USART1 TX / TIM5 UPD/OVF/TRG/BRK */
INTERRUPT void USART1_RX_TIM5_CC_IRQHandler(void); 
/* USART1 RX / TIM5 CAP */
INTERRUPT void I2C1_SPI2_IRQHandler(void); 
/* I2C1 / SPI2 */
#
endif
#
endif
/* __STM8L15x_IT_H */
---- stm8l15x_it.c ---- 
INTERRUPT_HANDLER(EXTI1_IRQHandler,9)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
GPIO_ToggleBits(GPIOC, GPIO_Pin_7);
}
---- stm8_interrupt_vector.c -----
#
include
''stm8l15x_it.h''
typedef void @far (*interrupt_handler_t)(void);
struct interrupt_vector {
unsigned char interrupt_instruction;
interrupt_handler_t interrupt_handler;
};
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, NonHandledInterrupt}, 
/* irq5 */
{0x82, NonHandledInterrupt}, 
/* irq6 */
{0x82, NonHandledInterrupt}, 
/* irq7 */
{0x82, NonHandledInterrupt}, 
/* irq8 */
{0x82, (interrupt_handler_t)EXTI1_IRQHandler}, 
/* 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 */
};

I cannot see my fault. The application compilies and runs, but when I press the Button it will always going back to the ISR an toggling the LED very very fast(using the debugger I saw this) #gpio-interrupt
2 REPLIES 2
rmottes
Associate II
Posted on March 15, 2015 at 21:08

If you have not already solved your problem.  Here is how I handle external interrupts.  This is for STM8S105 (same processor as STM8S discovery uses), also I use Raisonance not Cosmic, but the method is the same.  Hope this helps.

// Port E

#define X_IO9     GPIO_PIN_0

#define X_IO10    GPIO_PIN_1

#define X_IO11    GPIO_PIN_2

#define X_IO12    GPIO_PIN_3

// prototypes

void IO_NineToTwelve(void) interrupt 7;

void GPIO_Configuration(void);

// globals

u8 IOin;

void main(void)

{

  GPIO_Configuration();  // init GPIOs

  EXTI->CR2 = 0x02;      // set port E interrupts to falling edge only

  enableInterrupts();

  IOin = 0;

  for(;;)

  {

    if(IOin)

    {

      switch(IOin)

      {

        case RT:           // 1

          // call or do something

          break;

        case LF:           // 2

          // call or do something

          break;

        case UP:           // 3

          // call or do something

          break;

        case DN:           //4

          // call or do something

          break;

        default:

          IOin = 0;

          break;

      }

    }

  }

} // endof main()

void GPIO_Configuration(void)

{

  // reset GPIO

  GPIO_DeInit(GPIOE);

  

  // Init PORT E

  GPIO_Init(GPIOE, X_IO9,  GPIO_MODE_IN_PU_IT);

  GPIO_Init(GPIOE, X_IO10, GPIO_MODE_IN_PU_IT);

  GPIO_Init(GPIOE, X_IO11, GPIO_MODE_IN_PU_IT);

  GPIO_Init(GPIOE, X_IO12, GPIO_MODE_IN_PU_IT);

} // endof GPIO_Configuration()

void IO_NineToTwelve(void) interrupt 7

{

  u8 PortIn;

  PortIn = (~GPIO_ReadInputPin(GPIOE, GPIO_PIN_LNIB));  // only reads lower nybble of port

  if(PortIn & 0x01) IOin = 1;

  else

  if(PortIn & 0x02) IOin = 2;

  else

  if(PortIn & 0x04) IOin = 3;

  else

  if(PortIn & 0x08) IOin = 4;

  else

  IOin = 0;

} // endof IO_nineToTwelve()

upamir
Associate
Posted on May 31, 2015 at 12:32

hi

in main

GPIO_Init(GPIOC,

GPIO_Pin_1

, GPIO_Mode_In_FL_IT); GPIO_ExternalPullUpConfig(GPIOC,

GPIO_Pin_1

, ENABLE); EXTI_SetPinSensitivity(EXTI_Pin_1, EXTI_Trigger_Falling); ITC_SetSoftwarePriority(EXTI1_IRQn , ITC_PriorityLevel_2);

in int

INTERRUPT_HANDLER(EXTI1_IRQHandler,9)
{

GPIO_ToggleBits(GPIOC, GPIO_Pin_7);

EXTI_ClearITPendingBit(EXTI_IT_Pin

1

);

}