can anybody share code of reading data from uart by using uart interrupt method

ningappa BS
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

Postby ningappa BS » Wed May 16, 2018 5:28 am

i tried replacing 20 / portTICK_RATE_MS with portMAX_DELAY but by using this it is waiting infinite time in that reading function.
here am sharing my code

#define TXD_PIN 1
#define RXD_PIN 3

void init() {
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_0, &uart_config);
uart_set_pin(UART_NUM_0, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART_NUM_0, 1024, 1024, 0, NULL, 0);
}


void tx_task()
{

uint8_t *data = (uint8_t *) malloc(1024);
while (1) {
printf("hiiii\n");
int len = uart_read_bytes(UART_NUM_0, data, 1024,portMAX_DELAY);
printf("hello\n");
uart_write_bytes(UART_NUM_0, (const char *)data, len);

}
}


void app_main()
{
init();
xTaskCreate(tx_task, "uart_tx_task", 1024*2, NULL, 5, NULL);
}

ningappa BS
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

Postby ningappa BS » Wed May 16, 2018 11:57 am

ningappa BS wrote:i tried replacing 20 / portTICK_RATE_MS with portMAX_DELAY but by using this it is waiting infinite time in that reading function.
here am sharing my code

#define TXD_PIN 1
#define RXD_PIN 3

void init() {
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_0, &uart_config);
uart_set_pin(UART_NUM_0, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART_NUM_0, 1024, 1024, 0, NULL, 0);
}


void tx_task()
{

uint8_t *data = (uint8_t *) malloc(1024);
while (1) {
printf("hiiii\n");
int len = uart_read_bytes(UART_NUM_0, data, 1024,portMAX_DELAY);
printf("hello\n");
uart_write_bytes(UART_NUM_0, (const char *)data, len);

}
}


void app_main()
{
init();
xTaskCreate(tx_task, "uart_tx_task", 1024*2, NULL, 5, NULL);
}

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: can anybody share code of reading data from uart by using uart interrupt method

Postby Deouss » Wed May 16, 2018 4:19 pm

I am also interested in uart functions
Found reference to interrupt handler function

Code: Select all

esp_err_t uart_isr_register(uart_port_tuart_num, void (*fn)(void *), void *arg, int intr_alloc_flags, uart_isr_handle_t *handle, )
register UART interrupt handler(ISR).

Note
UART ISR handler will be attached to the same CPU core that this function is running on.
Return
ESP_OK Success
ESP_FAIL Parameter error
Parameters
uart_num: UART_NUM_0, UART_NUM_1 or UART_NUM_2
fn: Interrupt handler function.
arg: parameter for handler function
intr_alloc_flags: Flags used to allocate the interrupt. One or multiple (ORred) ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
handle: Pointer to return handle. If non-NULL, a handle for the interrupt will be returned here.
from https://esp-idf.readthedocs.io/en/v2.0/ ... #functions

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: can anybody share code of reading data from uart by using uart interrupt method

Postby ESP_Angus » Thu May 17, 2018 2:08 am

The docs you link here are for an older version of ESP-IDF, V2.0. In V3.0 (current stable release) the docs were rearranged, the equivalent docs page is now here:
http://esp-idf.readthedocs.io/en/v3.0/a ... /uart.html

To switch to the even newer master branch then you can use the version pop-up in the bottom left.
ningappa BS wrote:i tried replacing 20 / portTICK_RATE_MS with portMAX_DELAY but by using this it is waiting infinite time in that reading function.
Are you sure the UART is receiving data correctly? Are all the pins configured and connected correctly? If you use the unmodified "UART echo" example, does this work?

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: can anybody share code of reading data from uart by using uart interrupt method

Postby Deouss » Thu May 17, 2018 3:52 am

ESP_Angus wrote:
The docs you link here are for an older version of ESP-IDF, V2.0. In V3.0 (current stable release) the docs were rearranged, the equivalent docs page is now here:
http://esp-idf.readthedocs.io/en/v3.0/a ... /uart.html

To switch to the even newer master branch then you can use the version pop-up in the bottom left.
Do you know if there is a PDF document of whole documentation?

ningappa BS
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

Postby ningappa BS » Thu May 17, 2018 5:10 am

ESP_Angus wrote:
The docs you link here are for an older version of ESP-IDF, V2.0. In V3.0 (current stable release) the docs were rearranged, the equivalent docs page is now here:
http://esp-idf.readthedocs.io/en/v3.0/a ... /uart.html

To switch to the even newer master branch then you can use the version pop-up in the bottom left.
ningappa BS wrote:i tried replacing 20 / portTICK_RATE_MS with portMAX_DELAY but by using this it is waiting infinite time in that reading function.
Are you sure the UART is receiving data correctly? Are all the pins configured and connected correctly? If you use the unmodified "UART echo" example, does this work?
yes am sure UART working correctly, data receiving properly and unmodified echo example is working.
http://esp-idf.readthedocs.io/en/v3.0/a ... /uart.html
in this doc there is no function sequence.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: can anybody share code of reading data from uart by using uart interrupt method

Postby loboris » Thu May 17, 2018 7:43 am

Deouss wrote: Do you know if there is a PDF document of whole documentation?
Click on Read the Docs (bottom left) and select Downloads PDF.

ningappa BS
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

Postby ningappa BS » Fri May 18, 2018 9:56 am

ya it is there, is it there any driver code for uart interrupt method.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: can anybody share code of reading data from uart by using uart interrupt method

Postby loboris » Fri May 18, 2018 2:01 pm

ningappa BS wrote:ya it is there, is it there any driver code for uart interrupt method.
You can adapt the uart driver from esp-idf if it does not suits your needs.

Who is online

Users browsing this forum: No registered users and 88 guests