[SOLVED] INTERRUPT UART example work only one time and after hold
Posted: Mon Apr 01, 2019 11:51 am
Hello
I'm testing your ISR UART code and it work but ONLY ONE TIME!
After it hold and not receive nothing. Why??
Next question:
How save in string variable received data??
Please reply me soon.
Thanks in advice
I'm testing your ISR UART code and it work but ONLY ONE TIME!
After it hold and not receive nothing. Why??
Next question:
How save in string variable received data??
Code: Select all
String Received_Data = ??? (dtmp)
Thanks in advice
- /*
- * https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/uart.html#uart-api-setting-communication-pins
- */
- #include "driver/uart.h"
- #define NUMERO_PORTA_SERIALE UART_NUM_2
- #define BUF_SIZE (1024 * 2)
- #define RD_BUF_SIZE (1024)
- static QueueHandle_t uart2_queue;
- static const char * TAG = "";
- #define U2RXD 33
- #define U2TXD 32
- void setup() {
- Serial.begin(115200);
- //Configuro la porta Serial2 (tutti i parametri hanno anche un get per effettuare controlli)
- uart_config_t Configurazione_UART2 = {
- .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_param_config(NUMERO_PORTA_SERIALE, &Configurazione_UART2);
- //Firma: void esp_log_level_set(const char *tag, esp_log_level_tlevel)
- esp_log_level_set(TAG, ESP_LOG_INFO);
- //Firma: esp_err_tuart_set_pin(uart_port_tuart_num, int tx_io_num, int rx_io_num, int rts_io_num, int cts_io_num)
- uart_set_pin(NUMERO_PORTA_SERIALE, U2TXD, U2RXD, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
- //Firma: uart_driver_install(UART_NUM_2, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0));
- // uart_driver_install(Numero_porta, RXD_BUFFER, TXD_Buffer, event queue handle and size, flags to allocate an interrupt)
- uart_driver_install(NUMERO_PORTA_SERIALE, BUF_SIZE, BUF_SIZE, 20, &uart2_queue, 0);
- //Create a task to handler UART event from ISR
- xTaskCreate(UART_ISR_ROUTINE, "UART_ISR_ROUTINE", 2048, NULL, 12, NULL);
- }
- void loop() {
- Serial.println("Waiting data from SERIAL 2....");
- delay(1000);
- }
- static void UART_ISR_ROUTINE(void *pvParameters){
- uart_event_t event;
- size_t buffered_size;
- uint8_t* dtmp = (uint8_t*) malloc(RD_BUF_SIZE);
- Serial.println("INSIDE ISR");
- if(xQueueReceive(uart2_queue, (void * )&event, (portTickType)portMAX_DELAY)) {
- bzero(dtmp, RD_BUF_SIZE);
- ESP_LOGI(TAG, "uart[%d] event:", EX_UART_NUM);
- if (event.type==UART_DATA){
- //ESP_LOGI(TAG, "[UART DATA]: %d", event.size);
- uart_read_bytes(NUMERO_PORTA_SERIALE, dtmp, event.size, portMAX_DELAY);
- Serial.println("DATA= ");
- //ESP_LOGI(TAG, "[DATA EVT]:");
- //uart_write_bytes(NUMERO_PORTA_SERIALE, (const char*) dtmp, event.size);
- }// if event.type
- }//if xQuequeReceive
- free(dtmp);
- dtmp = NULL;
- vTaskDelete(NULL);
- }