ESP32 uart_read_bytes always 0

joe@shkila.com
Posts: 6
Joined: Tue Nov 13, 2018 6:23 am

ESP32 uart_read_bytes always 0

Postby joe@shkila.com » Wed Nov 21, 2018 11:00 am

I have ESP32-PICO-KIT v4
and i want to communicate with uart and serial port
i took the following code example:

Code: Select all

/* UART Echo Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "esp_log.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  (GPIO_NUM_4)
#define ECHO_TEST_RXD  (GPIO_NUM_5)
#define ECHO_TEST_RTS  (UART_PIN_NO_CHANGE)
#define ECHO_TEST_CTS  (UART_PIN_NO_CHANGE)

#define BUF_SIZE (1024)

static const char *TAG = "UART ECHO";

static void echo_task()
{
    /* Configure parameters of an UART driver,
     * communication pins and install the driver */
    uart_config_t uart_config = {
        .baud_rate = 9600,
        .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, &uart_config);
    uart_set_pin(UART_NUM_0, 21, 22, ECHO_TEST_RTS, ECHO_TEST_CTS);
    uart_driver_install(UART_NUM_0, 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_0, data, BUF_SIZE, 20 / portTICK_RATE_MS);
       if(len > 0)
		 ESP_LOGI(TAG, "[DATA EVT]: %s, %d",(const char *) data, len);
        uart_write_bytes(UART_NUM_0, (const char *) data, len);
    }
}

void app_main()
{
    xTaskCreate(echo_task, "uart_echo_task", 1024, NULL, 10, NULL);
}
uart_read_bytes always reutrns 0
i've attached a picture of the wiring

the chip connected to esp32 is increase the volt to fit the pc (sp3232ecp 0633L)

is there a guide or an example how to make it works?
thank you
Attachments
IMG_20181121_125546.jpg
IMG_20181121_125546.jpg (1.33 MiB) Viewed 3203 times

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 uart_read_bytes always 0

Postby WiFive » Wed Nov 21, 2018 1:30 pm

You should power the rs232 converter from 3v3 and you selected gpios 21 & 22 but your wires are not attached there.

Who is online

Users browsing this forum: Bing [Bot] and 80 guests