ESP8266 GPIO Interrupt

Sysprogs forums Forums VisualGDB ESP8266 GPIO Interrupt

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #23039
    RPP
    Participant

    Hi,

    I’m trying to config the ESP8266 GPIO4 to generate an interrupt as in the example on “ESP8266 Technical Reference Version 1.3 2017”, page 19, but didn’t work. The functions
    ETS_GPIO_INTR_DISABLE(), ETS_GPIO_INTR_ATTACH() and ETS_GPIO_INTR_ENABLE aren’t defined (I’m using the toolchains esp8266-gcc5.2.0-r15)

    Code:
    (…)
    static void ISR_shutoff(void *pvParameters)
    {
    Uint16 gpio_status = 0;
    gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
    if (gpio_status & (BIT(4)))
    {
    (…)
    }
    }

    (…)
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4);
    GPIO_DIS_OUTPUT(GPIO_ID_PIN(4));
    //ETS_GPIO_INTR_DISABLE();
    //ETS_GPIO_INTR_ATTACH(GPIO_INTERRUPT, NULL);
    gpio_pin_intr_state_set(GPIO_ID_PIN(4), GPIO_PIN_INTR_NEGEDGE);
    gpio_intr_handler_register((void *) ISR_shutoff, NULL);
    //ETS_GPIO_INTR_ENABLE();

    How can I configure ESP8266 GPIO to generate interrupt? Is there some GPIO interrupt example that I can use?

    #23040
    MystikReasons
    Participant
    #23043
    support
    Keymaster

    @MystikReasons, Thanks for sharing this!

    #23049
    RPP
    Participant

    Both examples uses “Arduino core for ESP8266 WiFi chip” and I would like an example using ESP8266_RTOS_SDK v2.x.x (I don’t known exactly wich RTOS SDK version “esp8266-gcc5.2.0-r15.exe” installs).

    I took a look at https://github.com/espressif/ESP8266_RTOS_SDK/tree/release/v2.x.x/examples, but there isn’t a GPIO interrupt example.

    There is an exemple for SDK v3.0 at https://github.com/espressif/ESP8266_RTOS_SDK/blob/release/v3.0/examples/peripherals/gpio/main/user_main.c, but I would have to change the SDK.

    Do you know where I can found an example for SDK v2.x.x?

    #23050
    RPP
    Participant

    I found an example at https://github.com/espressif/esp8266-rtos-sample-code/blob/master/02Peripheral/GPIOtest/user/user_main.c

    I did the following:

    1 – Declare the prototype “void gpio_config(GPIO_ConfigTypeDef *pGPIOConfig);” in the file “gpio.h”. This function is already defined at gpio.c;
    2 – Define the macros “#define ETS_GPIO_INTR_ENABLE() _xt_isr_unmask(1 << ETS_GPIO_INUM) //ENABLE INTERRUP//TS” and “#define ETS_GPIO_INTR_DISABLE() _xt_isr_mask(1 << ETS_GPIO_INUM) //DISABLE INTERRUPTS”
    in the file “ets_sys.h”
    3 – Configure the interrupt for the desired pin (in this case, GPIO4):
    GPIO_ConfigTypeDef io_in_conf;
    io_in_conf.GPIO_IntrType = GPIO_PIN_INTR_NEGEDGE;
    io_in_conf.GPIO_Mode = GPIO_Mode_Input;
    io_in_conf.GPIO_Pin = GPIO_Pin_4;
    io_in_conf.GPIO_Pullup = GPIO_PullUp_DIS;
    gpio_config(&io_in_conf);
    gpio_intr_handler_register((void *)ISR_shutoff, NULL);
    ETS_GPIO_INTR_ENABLE();
    4 – Create the interrupt handle:
    static void ISR_shutoff(void *pvParameters)
    {
    Uint16 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);

    if (gpio_status & (BIT(4)))
    {
    (…)
    }
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
    }

    Best regards,

    RPP

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.