Page 2 of 2

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

Posted: Wed May 16, 2018 5:28 am
by ningappa BS
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);
}

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

Posted: Wed May 16, 2018 11:57 am
by ningappa BS
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);
}

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

Posted: Wed May 16, 2018 4:19 pm
by Deouss
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

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

Posted: Thu May 17, 2018 2:08 am
by ESP_Angus
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?

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

Posted: Thu May 17, 2018 3:52 am
by Deouss
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?

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

Posted: Thu May 17, 2018 5:10 am
by ningappa BS
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.

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

Posted: Thu May 17, 2018 7:43 am
by loboris
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.

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

Posted: Fri May 18, 2018 9:56 am
by ningappa BS
ya it is there, is it there any driver code for uart interrupt method.

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

Posted: Fri May 18, 2018 2:01 pm
by loboris
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.