uart newbie question
Posted: Thu Oct 17, 2019 6:44 pm
Hello! This is my first post. I'm starting to develop with esp-idf and ESP32. I have experience with AVR and ARM Cortex-M0+ microcontrollers.
I installed the esp-idf stable without any issue, downloaded a clean project, coded a blink led and works fine. The board that I'm using is ESP32-S 1.1 board "Nodemcu".
I addded the code for a echo in the UART2 port, connected the board to a typical usb to uart (FTDI, tested) but the echo doesn't works. Also tested writing hello world to the uart2 and didnt work.
I think that must be a really easy solution but I can't find it.
This is my code:
the ftdi rx and tx are connected to pin 16 and 17 (yes, I tried inverting the tx/rx pin )
Any help?
thank you very much!
I installed the esp-idf stable without any issue, downloaded a clean project, coded a blink led and works fine. The board that I'm using is ESP32-S 1.1 board "Nodemcu".
I addded the code for a echo in the UART2 port, connected the board to a typical usb to uart (FTDI, tested) but the echo doesn't works. Also tested writing hello world to the uart2 and didnt work.
I think that must be a really easy solution but I can't find it.
This is my code:
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
/**
* This is an example which echos any data it receives on UART1 back to the sender,
* with hardware flow control turned off. It does not use UART driver event queue.
*
* - Port: UART1
* - Receive (Rx) buffer: on
* - Transmit (Tx) buffer: off
* - Flow control: off
* - Event queue: off
* - Pin assignment: see defines below
*/
#define ECHO_TEST_TXD (UART_PIN_NO_CHANGE)
#define ECHO_TEST_RXD (UART_PIN_NO_CHANGE)
#define ECHO_TEST_RTS (UART_PIN_NO_CHANGE)
#define ECHO_TEST_CTS (UART_PIN_NO_CHANGE)
#define BLINK_GPIO 2
#define BUF_SIZE (1024)
static void echo_task()
{
/* Configure parameters of an UART driver,
* communication pins and install the driver */
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_param_config(UART_NUM_2, &uart_config);
uart_set_pin(UART_NUM_2, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);
uart_driver_install(UART_NUM_2, BUF_SIZE * 2, 0, 0, NULL, 0);
// Configure a temporary buffer for the incoming data
uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
while (1) {
// Read data from the UART
int len = uart_read_bytes(UART_NUM_2, data, BUF_SIZE, 20 / portTICK_RATE_MS);
// Write data back to the UART
uart_write_bytes(UART_NUM_2, (const char *) data, len);
}
}
static void blink_task()
{
while(1) {
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(20 / portTICK_PERIOD_MS);
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void app_main()
{
gpio_pad_select_gpio(BLINK_GPIO);
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
xTaskCreate(echo_task, "uart_echo_task", 1024, NULL, 10, NULL);
xTaskCreate(blink_task, "blink_task", 1024, NULL, 10, NULL);
}
Any help?
thank you very much!