ESP32-S2先初始化GPIO0再初始化SPI,GPIO0操作失效
Posted: Wed Aug 09, 2023 3:50 pm
ESP32-S2使用GPIO0与SPI时,如果先初始化GPIO0,再初始化SPI,使用gpio_set_level函数,GPIO0并没有输出。而先初始化SPI,再初始化GPIO0,使用gpio_set_level控制GPIO0有效
这样写GPIO0操作无效
这样写GPIO0操作有效
请问这是什么原因
这样写GPIO0操作无效
Code: Select all
gpio_reset_pin(GPIO_NUM_0);
gpio_set_direction(GPIO_NUM_0, GPIO_MODE_OUTPUT);
gpio_set_level(GPIO_NUM_0, 1);
spi_device_handle_t spi;
spi_bus_config_t bus_cfg = {
.mosi_io_num = GPIO_NUM_37,
.miso_io_num = GPIO_NUM_46,
.sclk_io_num = GPIO_NUM_45,
.max_transfer_sz = 100,
};
spi_bus_initialize(SPI2_HOST, &bus_cfg, SPI_DMA_CH_AUTO);
spi_device_interface_config_t dev_cfg = {
.clock_speed_hz = 1 * 1000 * 1000,
.command_bits = 0,
.address_bits = 0,
.dummy_bits = 0,
.mode = 2,
.spics_io_num = -1,
.queue_size = 1,
};
spi_bus_add_device(SPI2_HOST, &dev_cfg, &spi);
while(1)
{
gpio_set_level(GPIO_NUM_0, 0);
gpio_set_level(GPIO_NUM_0, 1);
vTaskDelay(pdMS_TO_TICKS(100));
}
Code: Select all
gpio_reset_pin(GPIO_NUM_0);
gpio_set_direction(GPIO_NUM_0, GPIO_MODE_OUTPUT);
gpio_set_level(GPIO_NUM_0, 1);
spi_device_handle_t spi;
spi_bus_config_t bus_cfg = {
.mosi_io_num = GPIO_NUM_37,
.miso_io_num = GPIO_NUM_46,
.sclk_io_num = GPIO_NUM_45,
.max_transfer_sz = 100,
};
spi_bus_initialize(SPI2_HOST, &bus_cfg, SPI_DMA_CH_AUTO);
spi_device_interface_config_t dev_cfg = {
.clock_speed_hz = 1 * 1000 * 1000,
.command_bits = 0,
.address_bits = 0,
.dummy_bits = 0,
.mode = 2,
.spics_io_num = -1,
.queue_size = 1,
};
spi_bus_add_device(SPI2_HOST, &dev_cfg, &spi);
while(1)
{
gpio_set_level(GPIO_NUM_0, 0);
gpio_set_level(GPIO_NUM_0, 1);
vTaskDelay(pdMS_TO_TICKS(100));
}