UART keeps looping?
Hey all im using TX via USB to a GUI and im getting data but 2 issues. 1. it sends more than the string i ask it to and 2. It keeps looping even with a button. I have tried running it as a task even in a queue and same result
Edit: Image is the GUI and in quotes are what its receiving
/* UART asynchronous example, that uses separate RX and TX tasks
UART0 : TX= pin1 and RX= pin3 (USB)
*/
#include "esp_rom_gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h"
#include "driver/uart.h"
#include "hal/uart_types.h"
#include "soc/uart_struct.h"
#include "string.h"
#include "driver/gpio.h"
static const int RX_BUF_SIZE = 256;
static const int TX_BUF_SIZE = 256;
#define TXD_PIN 1
#define RXD_PIN 3
void UART(void)
{
const 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_driver_install(UART_NUM_0, RX_BUF_SIZE*2, TX_BUF_SIZE*2,0, NULL, 0);
uart_param_config(UART_NUM_0, &uart_config);
uart_set_pin(UART_NUM_0, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
}
void sendData(const char * data)
{
uart_write_bytes_with_break(UART_NUM_0, data, strlen(data),pdMS_TO_TICKS(300));
uart_flush(UART_NUM_0);
}
void tx_task(void *arg)
{
while(1)
{
if(gpio_get_level(34)==1)
{
sendData("hello");
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
}
void app_main(void)
{
UART();
// PullDown Button setup
esp_rom_gpio_pad_select_gpio(34);
gpio_set_direction(34, GPIO_MODE_INPUT);
gpio_set_pull_mode(34, GPIO_PULLDOWN_ONLY);
}