请教下,使用 esp32-S3-WROOM-1 N16R8 的模块,
目前想使用 2 个 spi 接口,
具体定义如下:
1. spi2 定义为驱动 lcd 显示屏,接口如下:
// LCD SPI 接口定义
#define GPIO_LCD_MOSI 0 //23 /*!< for 1-line SPI, this also refered as MOSI */
#define GPIO_LCD_MISO -1
#define GPIO_LCD_SCLK GPIO_LCD_SCK //19
#define GPIO_LCD_CS 40 //22
#define GPIO_LCD_DC 2 //21 H/L 命令数据选通端,H:数据,L:命令
#define GPIO_LCD_RESET -1 // 18 // 定义为 -1 表示不使用,屏蔽复位管脚,因为复位使用 io 扩展芯片实现
#define GPIO_LCD_BL -1 // 5 // 定义为 -1 表示不使用,屏蔽背光控制管脚,因为使用 io 扩展芯片实现
2. spi3 定义为驱动 外部 spi flash ,驱动 spi 接口的 flash 及 触摸屏 xpt2046 等
#define GPIO_T_MOSI (GPIO_NUM_19)
#define GPIO_T_MISO (GPIO_NUM_20)
#define GPIO_T_SCK (GPIO_NUM_46)
#define GPIO_SPI_MISO (GPIO_T_MISO)
#define GPIO_SPI_MOSI (GPIO_T_MOSI)
#define GPIO_SPI_SCLK (GPIO_T_SCK)
片选 使用外部扩展 的 io 芯片实现
3. 上述的定义功能,单独的使用的话,都是没有问题的,但是如果吧 spi2 及 spi3 同时编译后,发现 spi3 驱动 spi flash 及 xpt2046 的这组 spi 总线可以正常工作,spi2 驱动 lcd 的没有工作,不知道为何会这样呀 ??????
4. 相关的部分代码如下:
a. lcd 初始化
// 使用 spi bus 总线驱动的方式
void spi_master_init(_TFT_device_t * dev, int16_t GPIO_MOSI, int16_t GPIO_MISO, int16_t GPIO_SCLK,
int16_t GPIO_CS, int16_t GPIO_DC, int16_t GPIO_RESET, int16_t GPIO_BL)
{
ESP_LOGI(TAG, "GPIO_CS=%d",GPIO_CS);
if ( GPIO_CS >= 0 ) {
gpio_pad_select_gpio( GPIO_CS );
gpio_set_direction( GPIO_CS, GPIO_MODE_OUTPUT );
gpio_set_level( GPIO_CS, 0 );
}
ESP_LOGI(TAG, "GPIO_DC=%d",GPIO_DC);
gpio_pad_select_gpio( GPIO_DC );
gpio_set_direction( GPIO_DC, GPIO_MODE_OUTPUT );
gpio_set_level( GPIO_DC, 0 );
ESP_LOGI(TAG, "GPIO_MISO=%d",GPIO_MISO);
ESP_LOGI(TAG, "GPIO_MOSI=%d",GPIO_MOSI);
ESP_LOGI(TAG, "GPIO_SCLK=%d",GPIO_SCLK);
spi_config_t bus_conf = {
.miso_io_num = GPIO_MISO,
.mosi_io_num = GPIO_MOSI,
.sclk_io_num = GPIO_SCLK,
.quadwp = -1,
.quadhd = -1,
.max_transfer_sz = HX8357_TFTWIDTH * HX8357_TFTHEIGHT * sizeof(uint16_t)
};
spi_bus_handle_t lcd_bus_handle = NULL;
lcd_bus_handle = spi_bus_create(LCD_HOST, &bus_conf);
assert(lcd_bus_handle != NULL);
spi_device_config_t device_conf = {
.cs_io_num = GPIO_CS,
.clock_speed_hz = SPI_Frequency,
.mode = 0, // 这个设置为 2 工作不稳, 设置为 0 or 3 都可以正常稳定工作
};
spi_bus_device_handle_t device_handle = NULL;
device_handle = spi_bus_device_create(lcd_bus_handle, &device_conf);
printf( "\r\nLCD HX8357 - **** spi_bus_add_device addr = %p ****\r\n", &device_handle);
assert(device_handle != NULL);
dev->_dc = GPIO_DC;
dev->_bl = GPIO_BL;
dev->_SPIHandle = device_handle;
}
spi_master_init(&tft_handle, LCD_GPIO_MOSI, LCD_GPIO_MISO, LCD_GPIO_SCLK,
LCD_GPIO_CS, LCD_GPIO_DC, LCD_GPIO_RESET, LCD_GPIO_BL);
// ------------------------------------------------------------------------------------------------------------------------------
b. spi flash 初始化
spi_bus_device_handle_t device_handle_at = NULL;
//spi_bus_device_handle_t device_handle_xpt = NULL;
/*
at45db161 flash and xpt2046 触摸屏 都使用这个初始化函数
*/
esp_err_t bsp_generality_spi_init(void)
{
ESP_LOGI(TAG, "SPI_MISO=%d",SPI_MISO);
ESP_LOGI(TAG, "SPI_MOSI=%d",SPI_MOSI);
ESP_LOGI(TAG, "SPI_SCLK=%d",SPI_SCLK);
spi_config_t bus_conf = {
.miso_io_num = SPI_MISO,
.mosi_io_num = SPI_MOSI,
.sclk_io_num = SPI_SCLK,
.quadwp = -1,
.quadhd = -1,
.max_transfer_sz = 8192
};
spi_bus_handle_t spi_bus_handle = NULL;
spi_bus_handle = spi_bus_create(SPI_FLASH_HOST, &bus_conf);
if (NULL == spi_bus_handle) {
ESP_LOGE(TAG, "Failed create spi bus");
return ESP_FAIL;
}
// --------------------------------------------------------------------------------------------
spi_device_config_t device_conf = {
.cs_io_num = NULL_SPI_CS_PIN,
.clock_speed_hz = SPI_FlashFrequency,
.mode = 0, // 这个设置为 2 ,工作不稳
};
device_handle_at = spi_bus_device_create(spi_bus_handle, &device_conf); // 产生 at45db161 的应用句柄
if (NULL == device_handle_at) {
ESP_LOGE(TAG, "Failed create spi device device_handle_at");
return ESP_FAIL;
}
printf( "\r\ndevice_handle_at - **** spi_bus_add_device addr = %p ****\r\n", &device_handle_at);
return ESP_OK;
}
5. 移植自 esp-iot-solution-master 这个里面的相关程序
请教下,esp32-S3-WROOM-1 模块 spi2/spi3 能否同时使用 ?
Moderator: ESP_Bob
-
- Posts: 10
- Joined: Fri Mar 11, 2022 2:40 am
-
- Posts: 10
- Joined: Fri Mar 11, 2022 2:40 am
Re: 请教下,esp32-S3-WROOM-1 模块 spi2/spi3 能否同时使用 ?
都没有人遇到过这样的问题吗 ???
还是我问的太肤浅了呀 ??
还是我问的太肤浅了呀 ??
Re: 请教下,esp32-S3-WROOM-1 模块 spi2/spi3 能否同时使用 ?
Hello, have you found the solution .?
Sorry i dont speak chinese language.
I also want to use SPI3 because other are used by flash , PSRAM and another spi device.
Can you help please.
I just want to use SPI3 which i think i can map anywhere.
Sorry i dont speak chinese language.
I also want to use SPI3 because other are used by flash , PSRAM and another spi device.
Can you help please.
I just want to use SPI3 which i think i can map anywhere.
Who is online
Users browsing this forum: Baidu [Spider] and 17 guests