BLE triggers an interrupt from GPIO

sokolsok
Posts: 2
Joined: Sun Feb 25, 2024 12:58 pm

BLE triggers an interrupt from GPIO

Postby sokolsok » Thu May 16, 2024 10:10 pm

Hey there,
A quick intro: In my project, I need to use interrupts on the falling edge for GPIO36 and GPIO39. I'm using ESP32 and FreeRTOS. Everything works flawlessly up to this point. First, I initialize the interrupts:

Code: Select all

    
gpio_install_isr_service(0);
gpio_isr_handler_add(36, gpio_isr_handler, (void*) 36);
gpio_isr_handler_add(39, gpio_isr_handler, (void*) 39);
Next, I initialize the GPIO:

Code: Select all

esp_err_t gpio_init(gpio_int_type_t type, gpio_mode_t mode, gpio_pulldown_t pull_down, gpio_pullup_t pull_up, int no)
{
    gpio_config_t io_conf = {};

    io_conf.intr_type = type;
    io_conf.mode = mode;
    io_conf.pin_bit_mask = (1ULL << no);
    io_conf.pull_down_en = pull_down;
    io_conf.pull_up_en = pull_up;

    return gpio_config(&io_conf);
}

static esp_err_t keyboard_gpio_init(void)
{
	static esp_err_t err;

	gpio_init(GPIO_INTR_NEGEDGE, GPIO_MODE_INPUT, GPIO_PULLDOWN_DISABLE, GPIO_PULLUP_DISABLE, 39);
	if(err != ESP_OK){
		return err;
	}

	gpio_init(GPIO_INTR_NEGEDGE, GPIO_MODE_INPUT, GPIO_PULLDOWN_DISABLE, GPIO_PULLUP_DISABLE, 36);
	if(err != ESP_OK){
		return err;
	}

    return ESP_OK;
}
The interrupt function itself looks like this:

Code: Select all

void IRAM_ATTR gpio_isr_handler(void* arg)
{
    uint32_t gpio_num = (uint32_t) arg;
    xQueueSendFromISR(mcp23017_evt_queue, &gpio_num, NULL);
}
And the queue itself looks like this:

Code: Select all

    while(1)
    {
        if(xQueueReceive(mcp23017_evt_queue, &io_num, portMAX_DELAY))
        {
        	printf("GPIO: %ld\n", io_num);
        }
    }
So far, so good. The problem starts when I add BLE support based on the example: "nimble->bleprph."
As soon as I add it, interrupts for pins 36 and 39 are automatically and cyclically triggered... I should mention that Bluetooth works fine then.

I ran a test and added just the initialization of these two GPIOs and the interrupts to a clean BLE example, and it's exactly the same problem..
Any ideas on what might be going wrong? I've been stuck on this for 2 days now and can't figure it out...

Thanks a lot!

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 89 guests