Zephyr version: 2.4.99
OS: Linux
Board : nrf9160dk
I am trying to read data on UART 1 with interrupt. I have below shown portion in my code for enabling UART 1. (I am keeping UART0 for debugging, printk/printf)
const struct uart_config uart_cfg = { .baudrate = 9600, .parity = UART_CFG_PARITY_NONE, .stop_bits = UART_CFG_STOP_BITS_1, .data_bits = UART_CFG_DATA_BITS_8, .flow_ctrl = UART_CFG_FLOW_CTRL_NONE, }; f_uart = device_get_binding(DT_LABEL(DT_ALIAS(fuart))); if (f_uart == NULL) { printf("NB-IoT UART could not be enabled!\n"); return; } ret = uart_configure(f_uart, &uart_cfg); if (ret != 0) { printf("UART can not be configured!\n"); } uart_irq_rx_disable(f_uart); uart_irq_tx_disable(f_uart); uart_irq_callback_set(f_uart, uart_callback_fn); uart_irq_rx_enable(f_uart);
DTS file has below change:
* These aliases are provided for compatibility with samples */ aliases { led0 = &led0; led1 = &led1; led2 = &led2; led3 = &led3; pwm-led0 = &pwm_led0; sw0 = &button2; sw1 = &button3; sw2 = &button0; sw3 = &button1; fuart = &fuart; }; . . . fuart: &uart1 { status = "okay"; current-speed = <9600>; tx-pin = <1>; rx-pin = <0>; rts-pin = <14>; cts-pin = <15>; };
Prj.conf file is:
CONFIG_UART_1_ASYNC=y CONFIG_UART_ASYNC_API=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_UART_1_NRF_HW_ASYNC=y CONFIG_UART_1_NRF_HW_ASYNC_TIMER=2
UART Callback function
void uart_callback_fn(const struct device *dev, void *user_data) { ARG_UNUSED(user_data); uart_irq_update(dev); if (uart_irq_rx_ready(dev)) { rx_len = uart_fifo_read(dev, &rx_buf[0], 350); //printf("%s", rx_buf[0]); } }
I am sending data of approx 350 bytes from nrf52840dk to nrf9160dk. I do not want to use DMA as we have variable length of receiving data, but we can know the end of the data by a special character . The issue I am facing is My uart_callback_fn() is called for every byte received; uart_fifo_read() is not reading all the data at once. What I have observed is
- Even though I give 350 as 3rd param in uart_fifo_read(), it only reads 1 byte. This is due to read function implementation in uart_nrfx_uarte.c file which gets bounded in device_get_binding. The function only reads 1 byte. How can I not bind uart_nrfx_uarte.c ? How can I bind uart_nrfx_uart.c which has implementation of reading multiple bytes. What are the Kconfigs for this? I tried defining " compatible = "nordic,nrf-uart" " in DTS file but did not work.
- I also observed that only partial data was received. I suspect that might be due to buffer size. How can I increase the buffer size. I can neither find API nor Kconfig for this.
- There are some Kconfig like CONFIG_UART_NRFX_UARTE1 which are not given in Zephyr documentation. How can I know all other Kconfigs specific to nrf series Soc?
Thanks in advance!