esp32_gpio
This is an old revision of the document!
To set a pin as output, you must disable the modes “Interrupt” “pull Up” and “pull Down”, which would be rather input modes. You must configure the mode as “output mode” and you must specify which pins these changes affect using pin_bit_mask
gpio_config_t io_conf; io_conf.intr_type = GPIO_PIN_INTR_DISABLE;//disable interrupt io_conf.mode = GPIO_MODE_OUTPUT;//set as output mode io_conf.pin_bit_mask = (1ULL<<18);//bit mask of the pins that you want to set,e.g.GPIO18 io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;//disable pull-down mode io_conf.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode esp_err_t error=gpio_config(&io_conf);//configure GPIO with the given settings if(error!=ESP_OK){ printf("error configuring outputs \n"); }
To set a pin as input, You must put the mode ( io_conf.mode )as input and select if you want the low level to be interpreted as active or inactive using pull_down_en
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;//disable interrupt io_conf.mode = GPIO_MODE_INPUT;//set as inputmode io_conf.pin_bit_mask = (1ULL<<15);//bit mask of the pins that you want to set,e.g.GPIO15 io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode io_conf.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode esp_err_t error=gpio_config(&io_conf);//configure GPIO with the given settings if(error!=ESP_OK){ printf("error configuring inputs\n"); }
esp32_gpio.1677502982.txt.gz · Last modified: 2023/02/27 08:03 by 192.168.1.66