用的是esp32-s2-kaluga-1.3版本,idf是4.3
代码基本就是demo generic gpio 裁剪的 代码如下:
#define GPIO_OUTPUT_IO_0 18
#define GPIO_OUTPUT_IO_1 19
#define GPIO_OUTPUT_PIN_SEL ((1ULL<<GPIO_OUTPUT_IO_0) | (1ULL<<GPIO_OUTPUT_IO_1))
void app_main(void)
{
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);
int cnt = 0;
while(1) {
printf("cnt: %d\n", cnt++);
vTaskDelay(1000 / portTICK_RATE_MS);
esp_err_t err=ESP_FAIL;
err=gpio_set_level(GPIO_OUTPUT_IO_0, 1);
printf("GPIO[%d] intr, val: %d Err:%d\n", GPIO_OUTPUT_IO_0, gpio_get_level(GPIO_OUTPUT_IO_0),err);
err=gpio_set_level(GPIO_OUTPUT_IO_1, cnt % 2);
printf("GPIO[%d] intr, val: %d Err:%d\n", GPIO_OUTPUT_IO_1, gpio_get_level(GPIO_OUTPUT_IO_1),err);
}
}
但是串口显示
[11:44:17.079] [0;32mI (250) cpu_start: Starting scheduler on PRO CPU.[0m
[11:44:17.079] [0;32mI (256) gpio: GPIO[18]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 [0m
[11:44:17.095] [0;32mI (256) gpio: GPIO[19]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 [0m
[11:44:17.095] cnt: 0
[11:44:17.095] GPIO[18] intr, val: 0 Err:0
[11:44:18.087] GPIO[19] intr, val: 0 Err:0
[11:44:18.087] cnt: 1
[11:44:18.087] GPIO[18] intr, val: 0 Err:0
[11:44:19.079] GPIO[19] intr, val: 0 Err:0
[11:44:19.079] cnt: 2
[11:44:19.095] GPIO[18] intr, val: 0 Err:0
[11:44:20.087] GPIO[19] intr, val: 0 Err:0
[11:44:20.087] cnt: 3
[11:44:20.087] GPIO[18] intr, val: 0 Err:0
[11:44:21.079] GPIO[19] intr, val: 0 Err:0
[11:44:21.079] cnt: 4
[11:44:21.095] GPIO[18] intr, val: 0 Err:0
[11:44:22.087] GPIO[19] intr, val: 0 Err:0
[11:44:22.087] cnt: 5
[11:44:22.087]
感觉代码没有什么问题,请问esp32-s2-kaluga-1 在使用GPIO的情况下有特别注意事项么
by the way
自带的camera的程序没有问题,就是想自定义gpio的时候不行,感觉是不是哪里没弄好
咨询一个关于esp32-s2-kaluga-1 的GPIO的问题,很奇怪
Re: 咨询一个关于esp32-s2-kaluga-1 的GPIO的问题,很奇怪
typedef enum {
GPIO_MODE_DISABLE = GPIO_MODE_DEF_DISABLE, /*!< GPIO mode : disable input and output */
GPIO_MODE_INPUT = GPIO_MODE_DEF_INPUT, /*!< GPIO mode : input only */
GPIO_MODE_OUTPUT = GPIO_MODE_DEF_OUTPUT, /*!< GPIO mode : output only mode */
GPIO_MODE_OUTPUT_OD = ((GPIO_MODE_DEF_OUTPUT) | (GPIO_MODE_DEF_OD)), /*!< GPIO mode : output only with open-drain mode */
GPIO_MODE_INPUT_OUTPUT_OD = ((GPIO_MODE_DEF_INPUT) | (GPIO_MODE_DEF_OUTPUT) | (GPIO_MODE_DEF_OD)), /*!< GPIO mode : output and input with open-drain mode*/
GPIO_MODE_INPUT_OUTPUT = ((GPIO_MODE_DEF_INPUT) | (GPIO_MODE_DEF_OUTPUT)), /*!< GPIO mode : output and input mode */
} gpio_mode_t;
GPIO_MODE_DISABLE = GPIO_MODE_DEF_DISABLE, /*!< GPIO mode : disable input and output */
GPIO_MODE_INPUT = GPIO_MODE_DEF_INPUT, /*!< GPIO mode : input only */
GPIO_MODE_OUTPUT = GPIO_MODE_DEF_OUTPUT, /*!< GPIO mode : output only mode */
GPIO_MODE_OUTPUT_OD = ((GPIO_MODE_DEF_OUTPUT) | (GPIO_MODE_DEF_OD)), /*!< GPIO mode : output only with open-drain mode */
GPIO_MODE_INPUT_OUTPUT_OD = ((GPIO_MODE_DEF_INPUT) | (GPIO_MODE_DEF_OUTPUT) | (GPIO_MODE_DEF_OD)), /*!< GPIO mode : output and input with open-drain mode*/
GPIO_MODE_INPUT_OUTPUT = ((GPIO_MODE_DEF_INPUT) | (GPIO_MODE_DEF_OUTPUT)), /*!< GPIO mode : output and input mode */
} gpio_mode_t;
Re: 咨询一个关于esp32-s2-kaluga-1 的GPIO的问题,很奇怪
//set as output mode
io_conf.mode = GPIO_MODE_INPUT_OUTPUT;
貌似好像只有input 模式可以读取get_gpio_level
io_conf.mode = GPIO_MODE_INPUT_OUTPUT;
貌似好像只有input 模式可以读取get_gpio_level
Re: 咨询一个关于esp32-s2-kaluga-1 的GPIO的问题,很奇怪
你可以在 IDF 里看到这个函数的注释说明:If the pad is not configured for input (or input and output) the returned value is always 0.
Re: 咨询一个关于esp32-s2-kaluga-1 的GPIO的问题,很奇怪
/**
* @brief GPIO get input level
*
* @warning If the pad is not configured for input (or input and output) the returned value is always 0.
*
* @param gpio_num GPIO number. If you want to get the logic level of e.g. pin GPIO16, gpio_num should be GPIO_NUM_16 (16);
*
* @return
* - 0 the GPIO input level is 0
* - 1 the GPIO input level is 1
*
*/
int gpio_get_level(gpio_num_t gpio_num);
的确这样呵呵,粗心了
* @brief GPIO get input level
*
* @warning If the pad is not configured for input (or input and output) the returned value is always 0.
*
* @param gpio_num GPIO number. If you want to get the logic level of e.g. pin GPIO16, gpio_num should be GPIO_NUM_16 (16);
*
* @return
* - 0 the GPIO input level is 0
* - 1 the GPIO input level is 1
*
*/
int gpio_get_level(gpio_num_t gpio_num);
的确这样呵呵,粗心了
Who is online
Users browsing this forum: No registered users and 65 guests