This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF91: issues in setting the call back using uart_callback_set()

Hi,

I am able to set up uart async receive, but when I try to set the call back using uart_callback_set() so that i can call the uart_tx() routine to push the data out, but soon i call the uart_callback_set() the app crashes and in serial log it doesn't give any traces to see what went wrong.

{
    uart_irq_callback_set(dev, uart0_fifo_callback);
    uart_callback_set(dev, uart0_callback, dev);
    LOG_ERR("uart_callback_set: %d", status);
}

uart_tx(dev, buf, len, 100);

#UART CONFIGURATION
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_ASYNC_API=y
CONFIG_UART_0_NRF_FLOW_CONTROL=y

regards

KK

Parents Reply Children
  • The function uart_irq_callback_set and the function uart_callback_set are used for two different scenarios.

    uart_callback_set is used if "CONFIG_UART_ASYNC_API" is enabled, uart_irq_callback_set is used if its not.

    Now i got why its failing, i combined the both implementations, where they have to be used separately.

    I also looked at your reply in the thread https://devzone.nordicsemi.com/f/nordic-q-a/47218/continuously-package-send-on-uart

    void uart_cb(struct device *x)
    {
        :
        :
    	while (buf->len > written) {
    		written += uart_fifo_fill(x,
    					  &buf->data[written],
    					  buf->len - written);
    	}
    
    	while (!uart_irq_tx_complete(x)) {
    		/* Wait for the last byte to get
    		 * shifted out of the module
    		 */
    	}
        :
        :
    }

    And its working, but in your above implementation if i am sending out huge data it will be blocking and there are high changes that i miss the Rx interrupts so using CONFIG_UART_ASYNC_API could solve this problem?

    regards

    KK

  • Hi KK,

     

    kk2mkk said:
    And its working, but in your above implementation if i am sending out huge data it will be blocking and there are high changes that i miss the Rx interrupts so using CONFIG_UART_ASYNC_API could solve this problem?

     Since it does not really know how many bytes it will receive, it has a 1 byte RX DMA buffer set, and if you do not read it out fast enough, it will be overwritten. Using UART_ASYNC_API will solve this if you know how much data you should receive in a frame over a given time period for instance.

     

    Kind regards,

    Håkon

Related