UART Timeout doesn't work
Posted: Fri Jul 21, 2017 7:43 pm
I want to interface with another MCU via UART AT Commands. Sending those commands works perfectly, but I'm always stuck in the receive function. Any idea? My code:
Code: Select all
#define BUF_SIZE (1024)
static void at_task()
{
const int uart_num = UART_NUM_1;
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,
.rx_flow_ctrl_thresh = 122,
};
//Configure UART1 parameters
uart_param_config(uart_num, &uart_config);
//Set UART1 pins(TX: IO4, RX: I05, RTS: IO18, CTS: IO19)
uart_set_pin(uart_num, 4, 5, 18, 19);
//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);
uint8_t* data = (uint8_t*) malloc(BUF_SIZE);
uint8_t mystring[] = "at+version\r\n";
while(1) {
printf("Sending data to at \n");
//Write data back to UART
uart_write_bytes(uart_num, (const char*)mystring, strlen((const char*)mystring));
printf("Finished writing \n");
//Read data from UART
printf("Starting reading \n");
int len = uart_read_bytes(uart_num, data, 1024, 5 / portTICK_RATE_MS);
printf("Finished reading, %d bytes \n", len);
if(len > 0) {
printf("Got data: %s \n", data);
}
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
void app_main(void)
{
printf("ESP32 alive \n");
//A uart read/write example without event queue;
xTaskCreate(at_task, "at_task", 1024, NULL, 10, NULL);
}