Hello guys,
i have a problem with my esp32-Wroom-DevKit-V1. I have a Hart to Uart converter. The Uart signal, which I get on my RX-Pin from Uart2(pin16) doesn't match with the signal, which I get form my TX-Pin(pin.17).
I think the code ist very simple but I don't understand the problem, Can somebody help me?
Thanks for the Help!
Code:
#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 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 = 1200, // the Hart signal has a baud rate of 1200
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_ODD,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
};
//Uart Param Konfigurieren für UART 02
uart_param_config(UART_NUM_2, &uart_config);
// Set UART2 pins(TX: IO17 , RX: IO16 , RTS: IO18, CTS: IO19)
uart_set_pin(UART_NUM_2, 17,16 , 18, 19);
uart_driver_install(UART_NUM_2, BUF_SIZE * 2, 0, 0, NULL, 0);
//Uart Param Konfigurieren für UART 00
uart_param_config(UART_NUM_1, &uart_config);
// Set UART0 pins(TX: IO12 , RX: IO13 , RTS: IO22, CTS: IO23)
uart_set_pin(UART_NUM_1, 12 , 13 , 22 , 23);
uart_driver_install(UART_NUM_1, BUF_SIZE * 2, 0, 0, NULL, 0);
// Configure a temporary buffer for the incoming data
uint8_t *dataUA2 = (uint8_t *) malloc(BUF_SIZE);
uint8_t *dataUA1 = (uint8_t *) malloc(BUF_SIZE);
// CD for Uart2
gpio_pad_select_gpio(14);
gpio_set_direction(14,GPIO_MODE_INPUT);
// CD for Uart1
gpio_pad_select_gpio(27);
gpio_set_direction(27,GPIO_MODE_INPUT);
int lengthUA1 = 0;
int lengthUA2 = 0;
int i = 0;
int l = 0;
const int uart_num2 = UART_NUM_2;
const int uart_num1 = UART_NUM_1;
while(1)
{
uart_set_rts(uart_num2,0);
uart_set_rts(uart_num1,0);
//Einlesen der Verbindungsanfrage von UA2
if(gpio_get_level(14)==1) // The carried detected is on pin 14
{
lengthUA2 = uart_read_bytes(uart_num2, dataUA2, 100 , 20/portTICK_RATE_MS);
uart_set_rts(uart_num2,1);
uart_write_bytes(uart_num2, (const char *) dataUA2,lengthUA2);
uart_wait_tx_done(uart_num2,100/ portTICK_RATE_MS);
uart_set_rts(uart_num2,0);
vTaskDelay(1);
}
}
void app_main()
{
echo_task();
}
Uart signal on rx doesn't match with the tx signal
Who is online
Users browsing this forum: Bing [Bot] and 123 guests