ESP32 devkit esp-idf UART1 examle not working

blavoie
Posts: 16
Joined: Sat Jan 21, 2017 6:41 pm

ESP32 devkit esp-idf UART1 examle not working

Postby blavoie » Sun Jan 29, 2017 2:45 pm

I'm having problems with getting UART1 to send characters to the default GPIO pins and I've simplified the "uart_echo_test" function greatly to really break it down into the api calls. I'm just trying to stream a character (the letter L) to the GPIO output pins in accordance to the reference manual.

I have it that UART1 has GPIO9 for RX and GPIO10 for TX, when I put a scope on either pin I get a level high with no activity.

The code I'm using looks like this; I'm calling this from Main. I'm not using any buffers and for this test, I don't care if the code blocks until the TX is finished because I just want to see activity on the UART1 pins to make sure it's configured correctly.

I'm hoping someone can spot something I'm possibly missing or have configured incorrectly. Any help is greatly appreciated.


//an example of echo test with hardware flow control on UART1
void uart_echo_test()
{
int uart_num = UART_NUM_1;
uart_config_t uart_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_HW_FLOWCTRL_CTS_RTS,
.rx_flow_ctrl_thresh = 122,
};
//Configure UART1 parameters
uart_param_config(uart_num, &uart_config);

uart_set_pin(uart_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);

//Install UART driver( We don't need an event queue here)
//In this example we don't even use a buffer for sending data.
uart_driver_install(uart_num, BUF_SIZE * 2, 0, 0, NULL, 0);

uint8_t data[1];
data[0]='L';

int len = 1;
while(1) {
//Read data from UART
//int len = uart_read_bytes(uart_num, data, BUF_SIZE, 20 / portTICK_RATE_MS);
//Write data back to UART
uart_write_bytes(uart_num, (const char*) data, len);
//printf("sending = %c to uart1 \n",data[0]);
}
}

ESP_Angus
Posts: 571
Joined: Sun May 08, 2016 4:11 am

Re: ESP32 devkit esp-idf UART1 examle not working

Postby ESP_Angus » Sun Jan 29, 2017 9:24 pm

Hi blavoie,

A couple of things to try:

The code you posted doesn't provide any pin numbers to the uart_set_pins() call. You need to set the RX & TX pins here if not previously set.

GPIOs 9 & 10 are connected to the SPI flash chip by default, although only used in QIO mode. It's probably safer to use different pins (almost any apart from 6, 7, 9, 10, 11 which are SPI flash and 1, 3 which are UART0 default pins. Consult the ESP32 Pin List document from here for more.)


Angus

User avatar
kolban
Posts: 1065
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP32 devkit esp-idf UART1 examle not working

Postby kolban » Sun Jan 29, 2017 9:28 pm

See also this previous discussion on the concept/notion of "default" pins for UART:

viewtopic.php?f=13&t=1033
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

blavoie
Posts: 16
Joined: Sat Jan 21, 2017 6:41 pm

Re: ESP32 devkit esp-idf UART1 examle not working

Postby blavoie » Thu Feb 02, 2017 11:50 am

Thank you for your help with this, I was able to get the UART working by changing to a different set of pins just as you had suggested.

joicetm
Posts: 13
Joined: Mon Apr 10, 2017 12:47 pm

Re: ESP32 devkit esp-idf UART1 examle not working

Postby joicetm » Wed Apr 12, 2017 11:34 am

Hi esp_angus,

i am also trying to implement uart on my project, but its not working. even the example code[uart_echo] is not working. please help.
i also had tried by changing the rx and tx pin

example code i am using :
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "driver/uart.h"
#include "freertos/queue.h"
#include "esp_log.h"
#include "soc/uart_struct.h"

/**
* This is a example exaple which echos any data it receives on UART1 back to the sender, with hardware flow control
* turned on. It does not use UART driver event queue.
*
* - port: UART1
* - rx buffer: on
* - tx buffer: off
* - flow control: on
* - event queue: off
* - pin assignment: txd(io4), rxd(io5), rts(18), cts(19)
*/

#define ECHO_TEST_TXD (4)
#define ECHO_TEST_RXD (5)
#define ECHO_TEST_RTS (18)
#define ECHO_TEST_CTS (19)

#define BUF_SIZE (1024)

//an example of echo test with hardware flow control on UART1
static void echo_task()
{
const int uart_num = UART_NUM_1;
uart_config_t uart_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_CTS_RTS,
.rx_flow_ctrl_thresh = 122,
};
//Configure UART1 parameters
uart_param_config(uart_num, &uart_config);
//Set UART1 pins(TX: IO4, RX: I05, RTS: IO18, CTS: IO19)
uart_set_pin(uart_num, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);
//Install UART driver (we don't need an event queue here)
//In this example we don't even use a buffer for sending data.
uart_driver_install(uart_num, BUF_SIZE * 2, 0, 0, NULL, 0);

uint8_t* data [2]={7,8};
while(1) {
//Read data from UART
int len = uart_read_bytes(uart_num, data, BUF_SIZE, 20 / portTICK_RATE_MS);
//Write data back to UART
uart_write_bytes(uart_num, (const char*) data, len);
}
}

void app_main()
{
//A uart read/write example without event queue;
xTaskCreate(echo_task, "uart_echo_task", 1024, NULL, 10, NULL);
}

ESP_igrr
Posts: 859
Joined: Tue Dec 01, 2015 8:37 am

Re: ESP32 devkit esp-idf UART1 examle not working

Postby ESP_igrr » Thu Apr 13, 2017 9:04 am

Have you connected RTS and CTS pins listed in the example to your USB-UART converter? If you only connect TXD/RXD, example will not work because it enables hardware flow control.

blavoie
Posts: 16
Joined: Sat Jan 21, 2017 6:41 pm

Re: ESP32 devkit esp-idf UART1 examle not working

Postby blavoie » Thu Apr 13, 2017 10:19 am

Actually, with the board I'm using I only connected RXD and TXD and GND and it worked for me. I'm using a small board by FTDI, P/N FT230X. You can find it at Digi-key. I'm sure you've already done this, but double check to make sure that the connections are cross connected RX one side to TX on the other and vice versa and double check the ground connection also.

I found that UART1 worked with no changes to the pins.

rohit269
Posts: 12
Joined: Mon Sep 11, 2017 4:22 am

Re: ESP32 devkit esp-idf UART1 examle not working

Postby rohit269 » Thu Sep 14, 2017 1:48 pm

Hi, I'm having the same issue. I'm trying to send a data through UART1 but nothing appears on the Monitor. I have double checked the connections. I am not using flow control. I am using the following code. Please help.

#define ECHO_TEST_TXD (4)
#define ECHO_TEST_RXD (5)
// #define ECHO_TEST_RTS (18)
// #define ECHO_TEST_CTS (19)

#define BUF_SIZE (1024)

//an example of echo test with hardware flow control on UART1
static void echo_task()
{
const int uart_num = UART_NUM_1;
uart_config_t uart_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,
.rx_flow_ctrl_thresh = 122,
};
//Configure UART1 parameters
uart_param_config(uart_num, &uart_config);
//Set UART1 pins(TX: IO4, RX: I05, RTS: IO18, CTS: IO19)
uart_set_pin(uart_num, ECHO_TEST_TXD, ECHO_TEST_RXD, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
//Install UART driver (we don't need an event queue here)
//In this example we don't even use a buffer for sending data.
uart_driver_install(uart_num, BUF_SIZE * 2, 0, 0, NULL, 0);
int len = 1;
// uint8_t* data = (uint8_t*) malloc(BUF_SIZE);
uint8_t info[1];
info[0] = "r";
while(1) {
//Read data from UART
//int len = uart_read_bytes(uart_num, data, BUF_SIZE, 20 / portTICK_RATE_MS);
//Write data back to UART
uart_write_bytes(uart_num, (const char*)info, len);
}
}

void app_main()
{
//A uart read/write example without event queue;
xTaskCreate(echo_task, "uart_echo_task", 1024, NULL, 10, NULL);
}

blavoie
Posts: 16
Joined: Sat Jan 21, 2017 6:41 pm

Re: ESP32 devkit esp-idf UART1 examle not working

Postby blavoie » Thu Sep 14, 2017 4:16 pm

I see a couple of differences between your init code and mine.

I'm actually calling the pins by name.
//Set UART pins
uart_set_pin(uart_num, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);

I'm actually using a message queue, which won't affect what you're doing.
//Install UART driver, and get the queue.
uart_driver_install(uart_num, BUF_SIZE * 2, BUF_SIZE * 2, 10, &uart1_queue, 0);

Looks like you are trying to send the letter "r" repetitively out the UART txd pin and I'm not sure why it's not working. I'm using the same #defines for the pin names?

Who is online

Users browsing this forum: No registered users and 10 guests