Hi Friends,
I am very new to Programming with Microcontrollers.
I am unable to use this example program.
I changed the example's UART_NUM_1 to UART_NUM_0.
But unable send input.
Which software should I use to send serial inputs and
is there anything wrong in the code.
Thanks for help in advance.
/* 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 "driver/gpio.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 void echo_task(void *arg)
{
char ch[] = "This is great.....\n\n\n\0";
QueueHandle_t uart_queue;
/* 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,
.source_clk = UART_SCLK_APB,
};
uart_param_config(UART_NUM_0, &uart_config);
uart_set_pin(UART_NUM_0, ECHO_TEST_TXD, ECHO_TEST_RXD, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART_NUM_0, BUF_SIZE * 2, BUF_SIZE, 10, &uart_queue, 0);
uart_write_bytes(UART_NUM_0, (char *)ch, 21);
printf("\n\n\n");
// 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 = 0;
ESP_ERROR_CHECK(uart_get_buffered_data_len(UART_NUM_0, (size_t*)&len));
if(len > 0){
len = uart_read_bytes(UART_NUM_0, data, len, 100);
// Write data back to the UART
uart_write_bytes(UART_NUM_0, (const char *) data, len);
}else
uart_write_bytes(UART_NUM_0, "This is ridiculus\n", 18);
//uart_write_bytes(UART_NUM_0, (char *)ch, 21);
//printf("Inside....#####.....................................\n");
}
}
void app_main(void)
{
xTaskCreate(echo_task, "uart_echo_task", 1024, NULL, 10, NULL);
}
problem with reading from Serial Comm
Re: problem with reading from Serial Comm
Does the original code work for you (maybe your wires are wrong)?
Why do you want to switch to UART_0, you are using the examples pin definitions.
The stack is small especially as you are adding printf(). Increase from 1024 to 4000 FTM.
Waiting for 100mS before giving up makes this test tricky - you have to generate some serial output on your PC within 100mS before you echo "This is ...", maybe it does work but you are being swamped by "This is ..."
Perhaps UART_0 is reserved, try UART_2!
Coding is a lot of guess work, when stuck try something else!
Why do you want to switch to UART_0, you are using the examples pin definitions.
The stack is small especially as you are adding printf(). Increase from 1024 to 4000 FTM.
Waiting for 100mS before giving up makes this test tricky - you have to generate some serial output on your PC within 100mS before you echo "This is ...", maybe it does work but you are being swamped by "This is ..."
Perhaps UART_0 is reserved, try UART_2!
Coding is a lot of guess work, when stuck try something else!
& I also believe that IDF CAN should be fixed.
Who is online
Users browsing this forum: Bing [Bot], burtrum, Google [Bot] and 135 guests