GPIO配置完之后调用gpio_set_level()没有生效

gravity_john
Posts: 1
Joined: Tue Jul 16, 2024 7:17 am

GPIO配置完之后调用gpio_set_level()没有生效

Postby gravity_john » Mon Oct 14, 2024 12:53 pm

  1. #include "esp_log.h"
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "esp_spi_flash.h"
  5. #include "esp_partition.h"
  6. #include <driver/uart.h>
  7. #include <driver/gpio.h>
  8.  
  9. #define PARTITION_NAME "MCU_OTA"
  10. #define uart_num UART_NUM_2
  11.  
  12. #define stm_boot_pin 13
  13. #define stm_reset_pin 12
  14.  
  15. void app_main()
  16. {
  17.  
  18.     // gpio_reset_pin(stm_boot_pin);
  19.     // gpio_reset_pin(stm_reset_pin);
  20.     gpio_config_t app_gpio_config = {
  21.         .mode = GPIO_MODE_OUTPUT,            // 输出模式
  22.         .pin_bit_mask = (1ULL << stm_boot_pin), // 配置引脚 st en
  23.         .pull_up_en = GPIO_PULLUP_DISABLE,       // 不使能上拉
  24.         .pull_down_en = GPIO_PULLDOWN_DISABLE,  // 不使能下拉
  25.         .intr_type = GPIO_INTR_DISABLE          // 不使能引脚中断
  26.     };
  27.     esp_err_t errs = gpio_config(&app_gpio_config);
  28.     ESP_LOGI("MCU_OTA", "gpio_config : %d", errs);
  29.     errs = gpio_set_level(stm_boot_pin, 0);
  30.     ESP_LOGI("MCU_OTA", "gpio_set_level : %d", errs);
  31.  
  32.     // gpio_set_direction(stm_boot_pin, GPIO_MODE_OUTPUT);
  33.  
  34.     gpio_config_t app_gpio_config2 = {
  35.         .mode = GPIO_MODE_OUTPUT,             // 输出模式
  36.         .pin_bit_mask = (1ULL << stm_reset_pin), // 配置引脚
  37.         .pull_up_en = GPIO_PULLUP_DISABLE,       // 不使能上拉
  38.         .pull_down_en = GPIO_PULLDOWN_DISABLE,    // 不使能下拉
  39.         .intr_type = GPIO_INTR_DISABLE           // 不使能引脚中断
  40.     };
  41.     errs = gpio_config(&app_gpio_config2);
  42.     ESP_LOGI("MCU_OTA", "gpio_config : %d", errs);
  43.     errs = gpio_set_level(stm_reset_pin, 1);
  44.     ESP_LOGI("MCU_OTA", "gpio_set_level : %d", errs);
  45.  
  46.     vTaskDelay(1000 / portTICK_PERIOD_MS);
  47.     ESP_LOGI("MCU_OTA", "stm_boot_pin : %d", gpio_get_level(stm_boot_pin));
  48.     ESP_LOGI("MCU_OTA", "stm_reset_pin : %d", gpio_get_level(stm_reset_pin));
  49. }
  50.  

想配置高电平 但是一直没反应 打印的都是0 硬件应该没问题在Arduino环境下是可以拉高的


I (323) main_task: Started on CPU0
I (327) main_task: Calling app_main()
I (331) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (340) MCU_OTA: gpio_config : 0
I (344) MCU_OTA: gpio_set_level : 0
I (348) gpio: GPIO[12]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (358) MCU_OTA: gpio_config : 0
I (362) MCU_OTA: gpio_set_level : 0
I (1366) MCU_OTA: stm_boot_pin : 0
I (1366) MCU_OTA: stm_reset_pin : 0

Who is online

Users browsing this forum: Baidu [Spider] and 71 guests