can anybody share code of reading data from uart by using uart interrupt method
-
- Posts: 51
- Joined: Sat Mar 17, 2018 4:49 am
can anybody share code of reading data from uart by using uart interrupt method
hi everyone,
i wanted to read the data from uart by using uart interrupt method but here am not getting either sample code or example code.Any help would be appreciated.
thanks
i wanted to read the data from uart by using uart interrupt method but here am not getting either sample code or example code.Any help would be appreciated.
thanks
Re: can anybody share code of reading data from uart by using uart interrupt method
Can you describe what you've tried? If you have tried sample code, please provide links to that sample code. If something is not working, please describe the test/setup environment and any logs and/or description of the issue you are facing.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 51
- Joined: Sat Mar 17, 2018 4:49 am
Re: can anybody share code of reading data from uart by using uart interrupt method
actually now am working on polling method of uart reading, this is a driver code but i wanted flow sequence or example code of uart interrupt method.
thanks
thanks
-
- Posts: 51
- Joined: Sat Mar 17, 2018 4:49 am
Re: can anybody share code of reading data from uart by using uart interrupt method
Dear sir,
Actually my requirement is to read uart whenever we send external data (for example my keyboard input ) and it should not read in remaining time.
Actually my requirement is to read uart whenever we send external data (for example my keyboard input ) and it should not read in remaining time.
-
- Posts: 51
- Joined: Sat Mar 17, 2018 4:49 am
Re: can anybody share code of reading data from uart by using uart interrupt method
i want to receive some data serially on my esp32 for that i want to enable uart receive interrupt.
Last edited by ningappa BS on Tue May 15, 2018 11:55 am, edited 2 times in total.
Re: can anybody share code of reading data from uart by using uart interrupt method
If you're happy to use the ESP-IDF uart driver, the IDF example code uses an ISR to receive data (uart_driver_install is the call which enables this, with the specified buffer size):
https://github.com/espressif/esp-idf/bl ... main.c#L46
If you want to code your ISR directly, this is something else.
https://github.com/espressif/esp-idf/bl ... main.c#L46
If you want to code your ISR directly, this is something else.
-
- Posts: 51
- Joined: Sat Mar 17, 2018 4:49 am
Re: can anybody share code of reading data from uart by using uart interrupt method
here i do not want to read uart data continuously in a while loop instead it should read only when it get data. Like this, is there any method to read.kolban wrote:Can you describe what you've tried? If you have tried sample code, please provide links to that sample code. If something is not working, please describe the test/setup environment and any logs and/or description of the issue you are facing.
here am sharing my code
#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()
{
/* 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
};
uart_param_config(UART_NUM_1, &uart_config);
uart_set_pin(UART_NUM_1, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);
uart_driver_install(UART_NUM_1, BUF_SIZE * 2, 0, 0, NULL, 0);
// 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 = uart_read_bytes(UART_NUM_1, data, BUF_SIZE, 20 / portTICK_RATE_MS);
// Write data back to the UART
uart_write_bytes(UART_NUM_1, (const char *) data, len);
}
}
void app_main()
{
xTaskCreate(echo_task, "uart_echo_task", 1024, NULL, 10, NULL);
}
Re: can anybody share code of reading data from uart by using uart interrupt method
I think what you have written will do this, but the read from UART has a 20ms timeout so it's returning every 20ms regardless of whether there is data or not:ningappa BS wrote: here i do not want to read uart data continuously in a while loop instead it should read only when it get data. Like this, is there any method to read.
Change the 20 to a larger timeout (or replace the entire argument with portMAX_DELAY to block indefinitely) and the function will only return when there is data available on the UART.Code: Select all
int len = uart_read_bytes(UART_NUM_1, data, BUF_SIZE, 20 / portTICK_RATE_MS);
-
- Posts: 51
- Joined: Sat Mar 17, 2018 4:49 am
Re: can anybody share code of reading data from uart by using uart interrupt method
i tried with larger timeout but it is reading every timeout regardless data available,and used portMAX_DELAY but here it is not returning from that function.
Re: can anybody share code of reading data from uart by using uart interrupt method
If you do portmax_delay it should only return when there is data.
Who is online
Users browsing this forum: MicroController and 94 guests