-->
Page 1 of 1

ESP-12 Hardware interrupts not working

PostPosted: Tue Aug 04, 2015 12:30 am
by edfungus
I am using esp_mqtt and want to include a hardware interrupt. I have done searching and trying but not has worked... Any help would be greatly appreciated!

Here is the snippet of code of what I am doing:
Code: Select allstatic void pin13_interrupt(void *arg)
{
  uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
  //disable interrupt
  gpio_pin_intr_state_set(GPIO_ID_PIN(13), GPIO_PIN_INTR_DISABLE);

  os_delay_us(500000);
  INFO("i have been hit\n");

  //clear interrupt status
  GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(13));
  //enable interrupt
  gpio_pin_intr_state_set(GPIO_ID_PIN(0), 3);
}

void ICACHE_FLASH_ATTR user_init(void)
{
       ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
   ETS_GPIO_INTR_ATTACH(pin13_interrupt, 13); // GPIO13 interrupt handler
   PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO13); // Set GPIO13 function
   gpio_output_set(0, 0, 0, GPIO_ID_PIN(13)); // Set GPIO13 as input
   GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(13)); // Clear GPIO13 status
   gpio_pin_intr_state_set(GPIO_ID_PIN(13), 3); // Interrupt on any GPIO13 edge
   ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts
}

Re: ESP-12 Hardware interrupts not working

PostPosted: Tue Aug 04, 2015 1:46 am
by GigAHerZ
Maybe the huge delay causes watchdog to reset the chip? Print something out before the delay.

Re: ESP-12 Hardware interrupts not working

PostPosted: Tue Aug 04, 2015 11:11 pm
by edfungus
Hmm, gave that shot. Also tried with shorter delay and no delay with no luck. Are some pins not able to be interrupt pins?

Re: ESP-12 Hardware interrupts not working

PostPosted: Thu Aug 06, 2015 3:18 pm
by eriksl
Where did you get this code from? With a recent (say 1.2.0) version this is not the documented procedure. I guess it's for an old sdk version. For proper usage have a look at the gpio.h file and/or see my code as example (gpios.c from universal esp8266 bridge at github)