• Support
  • In UART, receiving a few characters instead of a full string

Dear All
I am using interrupt-driven UART callback. It is obviously working because I get 4-5 characters from the UART, but the remaining characters I can not get. I know that the characters are being transmitted.
In a nutshell, my UART receiver only can only process 4 characters.
It is an apparent resource issue on my device, but I am not sure what I should try. I have attempted to use CONFIG_MAIN_STACK_SIZE = 4096 and CONFIG_HEAP_MEM_POOL_SIZE = 8192 in prj.conf, but the issue has not been solved. It is unknown to me at this point why the rest of the characters do not generate interrupts.
I tried to get a list of errors by running uart_err_check(dev), but this call always returns 0 (no error). Any other debugging ideas ?
Any ideas are appreciated !

static void uart_callback(const struct device *dev, void *user_data)
{
    static uint8_t data[16];
    static int numchars;

    int ret;
    uint8_t err_code;

    	if (!uart_irq_update(dev)) {
		return;
	}

	if (!uart_irq_rx_ready(dev)) {
		return;
	}

	//stop_reason=uart_rx_stop_reason (dev);  // this one is for events, use with DMA
	//err_code = uart_err_check(dev);    //all err codes are 0x0
	/* read until FIFO empty */
	while (numchars = uart_fifo_read(dev, &data, 16)) {
            ret = ring_buf_put(&my_ring_buf, &data, numchars);
        }

} // end of uart_callback()`
9 days later

This is what I’m using successfully.

/* receive buffer used in UART ISR callback */
static char rx_buf[MSG_SIZE];
static int rx_buf_pos;

void serial_cb(const struct device *dev, void *user_data)
{
	uint8_t c=0;

	if (!uart_irq_update(uart_dev)) 
        {
		return;
	}

	while (uart_irq_rx_ready(uart_dev)) 
        {
		uart_fifo_read(uart_dev, &c, 1);
		rx_buf[rx_buf_pos++] = c;
	}
}
Terms and Conditions | Privacy Policy