Chat freely about anything...

User avatar
By edfungus
#24957 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
}
User avatar
By eriksl
#25224 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)