UART is not workinf

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

UART is not workinf

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

uart is not working

i am trying to set up uart on my project. but, even the example code is not working.

any help is much appreciated.

my code:

/* Uart Events 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 <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 (1)
#define ECHO_TEST_RXD (3)
#define ECHO_TEST_RTS (6)
#define ECHO_TEST_CTS (11)

#define BUF_SIZE (1024)

//an example of echo test with hardware flow control on UART1
//static void echo_task()


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

const int uart_num = UART_NUM_0;
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 = 120,
};
//Configure UART1 parameters
uart_param_config(uart_num, &uart_config);
// Set UART1 pins(TX: IO4, RX: I05, RTS: UART_PIN_NO_CHANGE, CTS: UART_PIN_NO_CHANGE)
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, 2048, 0, 0, NULL, 0);
uart_driver_install(uart_num, BUF_SIZE * 2, 0, 0, NULL, 0);

uint8_t* data = (uint8_t*) malloc(BUF_SIZE);
uint8_t dat[]={4,5,6,7};
int len=4;
data=dat;

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,&dat, len);
uart_write_bytes(uart_num,&dat, len);
}
}

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

Re: UART is not workinf

Postby kolban » Sat Apr 15, 2017 8:48 pm

What is the symptom of it "not working"?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

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

Re: UART is not working

Postby joicetm » Mon May 08, 2017 2:25 pm

Thank you so much MR.Kolban,

My esp-idf was not updated,the problem solved when i have updated it.
I found your book very helpful. i appreciate the effort you took to develop such a book on esp32.

madscientist_42
Posts: 95
Joined: Tue Feb 21, 2017 10:17 pm

Re: UART is not working

Postby madscientist_42 » Mon May 08, 2017 7:15 pm

joicetm wrote:Thank you so much MR.Kolban,

My esp-idf was not updated,the problem solved when i have updated it.
I found your book very helpful. i appreciate the effort you took to develop such a book on esp32.
He is quite helpful. I can only hope, as one of the embedded pros in the forums, I can eventually be as helpful as he's been up to this point on all fronts. :D

Who is online

Users browsing this forum: No registered users and 55 guests