gpio_set_pull_mode & gpio_pullup_en

username
Posts: 534
Joined: Thu May 03, 2018 1:18 pm

gpio_set_pull_mode & gpio_pullup_en

Postby username » Thu Jun 30, 2022 6:51 pm

Just curious when using gpio_set_pull_mode(), does it enable the pullup / pulldown by default or do you need to also call
gpio_pullup_en / gpio_pulldown_en ?

// Like to configure GPIO11 as input with pullup.

gpio_reset_pin(GPIO_NUM_11);
gpio_set_direction(GPIO_NUM_11, GPIO_MODE_INPUT);
gpio_set_pull_mode(GPIO_NUM_11, GPIO_PULLUP_ONLY);

// Do I need to do this extra step ?
gpio_pullup_en(GPIO_NUM_11);

User avatar
gtjoseph
Posts: 92
Joined: Fri Oct 15, 2021 10:55 pm

Re: gpio_set_pull_mode & gpio_pullup_en

Postby gtjoseph » Fri Jul 01, 2022 9:01 pm

gpio_set_pull_mode()'s purpose is to call the pullup/pulldown en/dis calls for you so no need to call gpio_pullup_en yourself...

Code: Select all

switch (pull) {
        case GPIO_PULLUP_ONLY:
            gpio_pulldown_dis(gpio_num);
            gpio_pullup_en(gpio_num);
            break;

        case GPIO_PULLDOWN_ONLY:
            gpio_pulldown_en(gpio_num);
            gpio_pullup_dis(gpio_num);
            break;

        case GPIO_PULLUP_PULLDOWN:
            gpio_pulldown_en(gpio_num);
            gpio_pullup_en(gpio_num);
            break;

        case GPIO_FLOATING:
            gpio_pulldown_dis(gpio_num);
            gpio_pullup_dis(gpio_num);
            break;

        default:
            ESP_LOGE(GPIO_TAG, "Unknown pull up/down mode,gpio_num=%u,pull=%u", gpio_num, pull);
            ret = ESP_ERR_INVALID_ARG;
            break;
    }

Who is online

Users browsing this forum: No registered users and 132 guests