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

UART Receice Data nrf52840

Hi everyone! I have probelem with receice data over UART. In the other MCU use core ARM as : STM32, NXP... when a byte is recieved, MCU has flag to notify. That is "interrupt". But in the NRF52, I can't see it. I always use "polling" mechanism to receive data. How can I use "interrupt" to receive data? thanks!!!

  • Hi,

    The UART peripheral interrupts are enabled in the INTENSET registers. I recommend using the UART driver(nrf_drv_uart), where this is handled for you. The app_uart_fifo library uses the nrf_drv_uart, and you can initialize the UART module like this using the app_uart_fifo:

    /**@snippet [UART Initialization] */
    static void uart_init(void)
    {
        uint32_t                     err_code;
        const app_uart_comm_params_t comm_params =
        {
            RX_PIN_NUMBER,
            TX_PIN_NUMBER,
            RTS_PIN_NUMBER,
            CTS_PIN_NUMBER,
            APP_UART_FLOW_CONTROL_DISABLED,
            false,
            UART_BAUDRATE_BAUDRATE_Baud115200
        };
    
        APP_UART_FIFO_INIT( &comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_event_handle,
                           APP_IRQ_PRIORITY_LOWEST,
                           err_code);
        APP_ERROR_CHECK(err_code);
    }
    

    When UART data has been received, you will get a APP_UART_DATA_READY event if you are using the app_uart_fifo. This is done in many of the examples in the SDK(e.g. ble_app_uart)

  • Thanks for your response. Can I use it as :

    void uart_callback_handle(app_uart_evt_t * p_event)
    {
        if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
        {
            APP_ERROR_HANDLER(p_event->data.error_communication);
        }
         if (p_event->evt_type == APP_UART_FIFO_ERROR)
        {
            APP_ERROR_HANDLER(p_event->data.error_code);
        }
    		if( p_event->evt_type == APP_UART_DATA_READY)
    		{
    			while(app_uart_get(&data)!=NRF_SUCCESS) {};
    			data_arr[index]=data;
    			index++;
    				if(index==10)
    				{index=0;xong=1;}
    		}		 
    }
    
Related