-->
Page 1 of 1

GPIO interrupt handler never gets called with RTOS SDK

PostPosted: Wed Jan 14, 2015 10:28 pm
by dxguidan
Hi,

I've tried tons of variations.. but for some reason my the interrupt handler never gets called.

I'm using ESP8266_01. (only GPIO0 and GPIO2 are available).

I can read the GPIOs as input (pulldown/pullup) and set them as output, so my code is not completely off - just can't get the damn interrupts to work.

Here is a very simplified version of what I'm trying to down (stripped down to the bone):

Code: Select allvoid main_int_handler()
{
   printf("main_int_callback!\n");
   int i;
   uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
   for (i = 0; i < MAX_PINS; i++)
   {
      if ((gpio_status & BIT(i)) )
      {
         printf("triggered on int: %d\n", i);
         //disable interrupt
         gpio_pin_intr_state_set(GPIO_ID_PIN(i), GPIO_PIN_INTR_DISABLE);
                        // call func here
         //clear interrupt status
         GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(i));
         // restore
         gpio_pin_intr_state_set(GPIO_ID_PIN(i), g_arrPins[i].int_mode);
      }
   }   
}

void ICACHE_FLASH_ATTR registerInterrupt(int pin, GPIO_INT_TYPE mode)
{
   portENTER_CRITICAL();

   // disable open drain
   GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin)),
                                         GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin))) & (~ GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)));
   
   //clear interrupt status
   GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pin));

        // set the mode   
   gpio_pin_intr_state_set(GPIO_ID_PIN(pin), mode);

   portEXIT_CRITICAL();
}

void init()
{
   // Register main callback (GPIOs default to INPUT)
   gpio_intr_handler_register(main_int_callback);
   registerInterrupt(0,  GPIO_PIN_INTR_ANYEDGE);
   registerInterrupt(2,  GPIO_PIN_INTR_ANYEDGE);
}



My handler never gets called. I alternate between GND and VCC for the GPIOs, and while I can read them correctly as input - they never trigger anything.

Any ideas?
Much appreciated!

Re: GPIO interrupt handler never gets called with RTOS SDK

PostPosted: Thu Jan 15, 2015 2:43 am
by hreintke
dxguidan,
Quick check compared to my code.

I do have :
Code: Select all    _xt_isr_attach(ETS_GPIO_INUM, (_xt_isr)interruptHandler);
    _xt_isr_unmask(1<<ETS_GPIO_INUM);


instead of your :
Code: Select allgpio_intr_handler_register(main_int_callback);


and don't have the :

Code: Select all   // disable open drain
   GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin)),
                                         GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin))) & (~ GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)));


Regards,
Herman

Re: GPIO interrupt handler never gets called with RTOS SDK

PostPosted: Thu Jan 15, 2015 9:10 am
by dxguidan
Herman you're a genius.

I was missing _xt_isr_unmask(1<<ETS_GPIO_INUM); - it was masked off by default.

Thanks!