[已解决] ESP32-CAM摄像头应用UART乱码问题求助

simonliu009
Posts: 6
Joined: Mon May 20, 2019 1:12 am

[已解决] ESP32-CAM摄像头应用UART乱码问题求助

Postby simonliu009 » Mon May 20, 2019 2:17 am

我最近使用ESP32-CAM做一个图像采集项目,基于这个代码 https://github.com/InfiniteYuan1/esp32- ... web_server,源代码是没问题的。然后我移除了http和WIFI,也能成功采集到图像。
但是我在初始化串口以后,发现串口定期发送乱码干扰串口输出。开机一段时间后,可以看到uart_write_bytes()和printf()发送的内容在乱码中间可以正常显示。


串口初始化代码:

Code: Select all

#define RX0_BUF_SIZE 		(1024)
#define TX0_BUF_SIZE 		(512)

#define RX2_BUF_SIZE 		(1024)
#define TX2_BUF_SIZE 		(512)
#define TXD2_PIN 			(GPIO_NUM_12)
#define RXD2_PIN 			(GPIO_NUM_13)
static QueueHandle_t uart0_queue;
static QueueHandle_t uart2_queue;

void uart_init(void)
{

    //串口参数配置->uart0
	    uart_config_t uart0_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };

	uart_param_config(UART_NUM_0, &uart0_config);		//设置串口
	
	uart_set_pin(UART_NUM_0, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
	//注册串口服务即使能+设置缓存区大小
    uart_driver_install(UART_NUM_0, RX0_BUF_SIZE * 2, TX0_BUF_SIZE * 2, 20, &uart0_queue, 0);

	//串口参数配置->uart2
	    uart_config_t uart2_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };
	uart_param_config(UART_NUM_2, &uart2_config);		//设置串口
	//IO映射-> T:IO12  R:IO13
	uart_set_pin(UART_NUM_2, TXD2_PIN, RXD2_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
	//注册串口服务即使能+设置缓存区大小
    uart_driver_install(UART_NUM_2, RX0_BUF_SIZE * 2, TX0_BUF_SIZE * 2, 20, &uart2_queue, 0);

}

Code: Select all

void app_uart_main()
{
	uart_init();
}

void uarttest()
{
    uart_write_bytes(UART_NUM_0, " uart0 test OK ", strlen(" uart0 test OK "));	
}

启动以后我运行了几个软件timer,clock_timer_handle中定时调用uarttest():

Code: Select all

	err = esp_timer_create(&ntp_timer_arg, &ntp_timer_handle);
	err = esp_timer_start_once(ntp_timer_handle, 5 * 1000 * 1000);
	printf("ntp_timer创建状态码: %s", err == ESP_OK ? "ok!\r\n" : "failed!\r\n");

	//开始创建一个重复周期的定时器并且执行
	err = esp_timer_create(&camera_timer_arg, &camera_timer_handle);
	err = esp_timer_start_periodic(camera_timer_handle, 10 * 1000 * 1000);
	printf("camera_timer创建状态码: %s", err == ESP_OK ? "ok!\r\n" : "failed!\r\n");

    err = esp_timer_create(&clock_timer_arg, &clock_timer_handle);
	err = esp_timer_start_periodic(clock_timer_handle, 1 * 1000 * 1000);
	printf("clock_timer创建状态码: %s", err == ESP_OK ? "ok!\r\n" : "failed!\r\n");
摄像头引脚定义,里面没有涉及UART2的12和13引脚:

Code: Select all

#elif CONFIG_CAMERA_MODEL_AI_THINKER
#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0
#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27

#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22
截图说明:乱码后面部分内容可以识别,其中`uart0 test OK`是uart_write_bytes()发送的,其他可识别内容是printf()发送的。
Attachments
QQ20190520-094853@2x.png
QQ20190520-094853@2x.png (408.07 KiB) Viewed 8252 times
Last edited by simonliu009 on Mon May 20, 2019 6:23 am, edited 2 times in total.

simonliu009
Posts: 6
Joined: Mon May 20, 2019 1:12 am

Re: UART乱码问题求助

Postby simonliu009 » Mon May 20, 2019 3:50 am

更新一下:
那个源码应该是基于ESP-who的
然后今天测了一下,基于idf-template,先运行uart和定时器,都是OK的。
然后加入esp-camera的相关component,就出现乱码了。基本上确定是和camera component有关系。

simonliu009
Posts: 6
Joined: Mon May 20, 2019 1:12 am

Re: ESP32-CAM摄像头应用UART乱码问题求助

Postby simonliu009 » Mon May 20, 2019 6:22 am

找到解决方法了
用了官方的esp-who来做没问题了。最开始我用的那个repo就有问题。我还以为两个差别不大。

Who is online

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