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

Align UART transmission/reception with GPIO pin signaling low/high

How do I align UART transmission/reception with GPIO pin signaling low/high? I wanted to do this because BLE chip is receiving the Product ID & device name from microcontroller over uart & it is also sending the HID output reports over uart. The steps/logic I would like to implement -

(A) After receiving the Product ID & device name, pull GPIO pin low. (There is more logic included)

I tried this but the pin goes low, before all data is read. I was tracking the error code to return NRF_SUCCESS but that does not help. I was trying to do something like this for app_uart_put() & app_uart_get()

for(ind = 0; ind < BLE_INFO_FRAME_LEN; ind++)
	{
		//NRF_LOG_RAW_INFO("Byte: %d\n", ble_info_frame[ind]);
		while (app_uart_put(ble_info_frame[ind]) != NRF_SUCCESS);
	}
	if(ind == BLE_INFO_FRAME_LEN)
	{
		nrf_gpio_pin_clear(0);
	}

(B) After transmitting HID output report, pull GPIO pin high

Is there a flag or interrupt which tracks this?

Parents Reply Children
  • Hi,

     

    I am very sorry for the late reply. The app_uart library sends byte-for-byte, so you're right: this will not work properly.

    You could do something like this:

    for(ind = 0; ind < BLE_INFO_FRAME_LEN; ind++)
    	{
    		//NRF_LOG_RAW_INFO("Byte: %d\n", ble_info_frame[ind]);
    		while (app_uart_put(ble_info_frame[ind]) != NRF_SUCCESS);
    	}
    	// If last byte, set flag to clear pin in uart_handler()
    	if(ind == BLE_INFO_FRAME_LEN)
    	{
    		clear_pin = true;
    	}

     And in the uart handler:

    void uart_error_handle(app_uart_evt_t * p_event)
    {
    	uint32_t err_code;	
    	switch(p_event->evt_type)
    	{			
    	    case APP_UART_TX_EMPTY:
    	        if (clear_pin == true)
    	        {
    	            clear_pin = false;
    	            nrf_gpio_pin_clear(0);
    	        }
    	    break;
    		case APP_UART_COMMUNICATION_ERROR:
    			break;
    		case APP_UART_FIFO_ERROR:
    			break;
    		default:
    			break;
    	}
    }

    Could you try this and see if it works better?

     

    Another alternative can be to call nrf_drv_uart_tx() directly, as you can then set the length of the overall transmission in one transaction.

     

    Kind regards,

    Håkon

Related