Page 1 of 1

pulldown enable blocks

Posted: Fri Sep 27, 2019 2:37 pm
by oliverbru
Hello,

Sorry to ask basic things but, I tried this code:

Code: Select all

/* Hello World Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "sdkconfig.h"

#define BLINK_GPIO_GREEN 25
#define BUTTON GPIO_NUM_12
#define ESP_INTR_FLAG_DEFAULT 0

 int BUTTON_PRESSED;

void blink_task(void *pvParameter)
{
    while (1)
    { 
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        BUTTON_PRESSED = gpio_get_level(BUTTON);
        ESP_LOGI("test", "BUTTON STATE : %d", BUTTON_PRESSED);
        gpio_set_level(BLINK_GPIO_GREEN, BUTTON_PRESSED);
    }
}


static void IRAM_ATTR gpio_isr_handler()
{
    BUTTON_PRESSED = gpio_get_level(BUTTON);
    ets_printf("Button state : %d\n", BUTTON_PRESSED);
}

void app_main()
{
   
    gpio_pad_select_gpio(BLINK_GPIO_GREEN);
    gpio_set_direction(BLINK_GPIO_GREEN, GPIO_MODE_OUTPUT);

    gpio_config_t btn_config;
    btn_config.intr_type = GPIO_INTR_ANYEDGE ;
    btn_config.mode = GPIO_MODE_INPUT;               //Set as Input
    btn_config.pin_bit_mask = (1ULL << BUTTON); //Bitmask
    btn_config.pull_up_en = GPIO_PULLUP_DISABLE;     //Disable pullup
    btn_config.pull_down_en = GPIO_PULLDOWN_ENABLE; //Enable pulldown
    gpio_config(&btn_config);
    BUTTON_PRESSED = gpio_get_level(BUTTON);
    //install gpio isr service
    gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);

    //hook isr handler for specific gpio pin
    gpio_isr_handler_add(BUTTON, gpio_isr_handler, NULL);
    
    xTaskCreate(&blink_task, "blink_task", 1024*4, NULL, 1, NULL);
}
If I set GPIO_PULLDOWN_DISABLE, I have bounces.
Since I set GPIO_PULLDOWN_ENABLE, the interruption is not called and the button does not work.

I do not understand.

Regards,

Re: pulldown enable blocks

Posted: Fri Sep 27, 2019 5:32 pm
by mikemoy
How is your button wired up ?

Re: pulldown enable blocks

Posted: Fri Sep 27, 2019 11:00 pm
by oliverbru
I attached the image.

Re: pulldown enable blocks

Posted: Sat Sep 28, 2019 1:24 am
by mikemoy
Thanks, however there is no way i can tell by the photo. Does your button have a pullup resistor? It does not look like it.,

Re: pulldown enable blocks

Posted: Sat Sep 28, 2019 7:53 am
by WiFive
The button is connected to ground and the pulldown is connected to ground so all you will get is ground