ext interrupt for stm8l

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
nupagachi85
Posts: 8
Joined: Tue Sep 25, 2012 4:58 am

ext interrupt for stm8l

Post by nupagachi85 »

Dear,

I make interrupt for Pin PE0, but when I press key and keep it low, the interrupt alway happens.
Here is my code:

Code: Select all

/*main.c*/
static msg_t Thread1(void *arg) {
  (void)arg;
  chRegSetThreadName("blinker");
  while (TRUE) {
    palSetPad(GPIOA, 5);
    chThdSleepMilliseconds(500);
    palClearPad(GPIOA, 5);
    chThdSleepMilliseconds(500);
   R_LED = 1;
  B_LED = 1;
 
  }
  return 0;
}

static msg_t Thread2(void *arg) {

  (void)arg;
  chRegSetThreadName("uart");
  while (TRUE) {
    palSetPad(GPIOA, 4);
    //palSetPad(GPIOA, 5);
    chThdSleepMilliseconds(250);
    palClearPad(GPIOA, 4);
   // palClearPad(GPIOA, 5);
   
    chThdSleepMilliseconds(250);
   R_LED = 1;
  }
  return 0;
}
/*
 * Application entry point.
 */
void main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Activates the serial driver 1 using the driver default configuration.
   * The STM8L-Discovery requires USART1 pins remapping on PA2 and PA3.
   */
 // SYSCFG->RMPCR1 = 0x1C;/*remap*/

   // EXTI->CR1 &=  (uint8_t)(~EXTI_CR1_P0IS);
   // EXTI->CR1 |= (uint8_t)((uint8_t)(0x02) << 0x00);

    
  sdStart(&SD1, NULL);
 
  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  //chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL);
 

  /*
   * Normal main() thread activity.
   */
  while (TRUE) {
    if (palReadPad(GPIOC, PC_BUTTON) == PAL_LOW)
         //TestThread(&SD1);
     
      if(R_LED == 1){
            sdWrite(&SD1, "R_LED ON\r\n", 10);
      R_LED = 0;   
         }     
   if(B_LED == 1){
            sdWrite(&SD1, "R_LED OFF\r\n", 11);
      B_LED = 0;   
         }
    //chThdSleepMilliseconds(1000);
  }
}

/*shared_isr.c*/

delayms(u16 ms)
{
 u16 i = 0;
 for(i = 0; i<ms;i++)
    nop();
}
CH_IRQ_HANDLER(8) {
  CH_IRQ_PROLOGUE();
  chSysLockFromIsr();
  /* Invocation of some I-Class system APIs, never preemptable.*/
 
  EXTI->SR1 = 0x0001;/*clear interrupt*/
  delayms(300);

  if (palReadPad(GPIOE, 0) == PAL_LOW)
  {
      palTogglePad(GPIOA, 4);

  }
  chSysUnlockFromIsr();

  CH_IRQ_EPILOGUE();
}



Please help me.
Thanks
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ext interrupt for stm8l

Post by Giovanni »

I don't understand exactly your problem but I see two things in that code:
1) The EXTI initialization is commented out so it should not be active.
2) You insert a delay into an ISR, this is wrong in general.

Giovanni
nupagachi85
Posts: 8
Joined: Tue Sep 25, 2012 4:58 am

Re: ext interrupt for stm8l

Post by nupagachi85 »

Hi Giovanni,

Have you got any example for stm8? I can not find ext setting template.
1)How to active it?
2)My purpose is prevent noise from key.

I just want to setting a simple ext interrupt, but maybe I have 1 mistake in my code

regards
Thinh
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ext interrupt for stm8l

Post by Giovanni »

Hi,

I don't have any example for STM8 but using EXTI is very sensitive to noise, you could sample a pin using a software timer and implement a debounce: set a counter to 10 (example) and decrement it every mS until it reaches zero then trigger the "key pressed" event.

Giovanni
Post Reply