<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Align UART transmission/reception with GPIO pin signaling low/high</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/47228/align-uart-transmission-reception-with-gpio-pin-signaling-low-high</link><description>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 &amp;amp; device name from microcontroller over uart &amp;amp; it is also sending the HID output reports over uart. The steps</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 23 May 2019 07:16:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/47228/align-uart-transmission-reception-with-gpio-pin-signaling-low-high" /><item><title>RE: Align UART transmission/reception with GPIO pin signaling low/high</title><link>https://devzone.nordicsemi.com/thread/188696?ContentTypeID=1</link><pubDate>Thu, 23 May 2019 07:16:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf03c50b-7831-4729-8d52-12c46c533ac8</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am very sorry for the late reply. The app_uart library sends byte-for-byte, so you&amp;#39;re right: this will not work properly.&lt;/p&gt;
&lt;p&gt;You could do something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;for(ind = 0; ind &amp;lt; BLE_INFO_FRAME_LEN; ind++)
	{
		//NRF_LOG_RAW_INFO(&amp;quot;Byte: %d\n&amp;quot;, 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;
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;And in the uart handler:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void uart_error_handle(app_uart_evt_t * p_event)
{
	uint32_t err_code;	
	switch(p_event-&amp;gt;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;
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Could you try this and see if it works better?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Align UART transmission/reception with GPIO pin signaling low/high</title><link>https://devzone.nordicsemi.com/thread/187397?ContentTypeID=1</link><pubDate>Thu, 16 May 2019 05:35:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4b62ed5-8d42-4125-aef2-c607b060a918</guid><dc:creator>bscdb</dc:creator><description>&lt;p&gt;Please reply..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Align UART transmission/reception with GPIO pin signaling low/high</title><link>https://devzone.nordicsemi.com/thread/187091?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 21:51:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2522fef4-8fc1-48f9-abd9-4e3333791966</guid><dc:creator>bscdb</dc:creator><description>&lt;p&gt;My error handler&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void uart_error_handle(app_uart_evt_t * p_event)
{
	uint32_t err_code;	
	switch(p_event-&amp;gt;evt_type)
	{			
	    case APP_UART_TX_EMPTY:
	        nrf_gpio_pin_clear(0);
	    break;
		case APP_UART_COMMUNICATION_ERROR:
			break;
		case APP_UART_FIFO_ERROR:
			break;
		default:
			break;
	}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Align UART transmission/reception with GPIO pin signaling low/high</title><link>https://devzone.nordicsemi.com/thread/187090?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 21:47:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61506b6a-5ce7-45aa-bd0a-bb2e13ff7f3c</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;What was the code that you added to the event handler?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Align UART transmission/reception with GPIO pin signaling low/high</title><link>https://devzone.nordicsemi.com/thread/187038?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 14:34:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:555dd0c3-2a4d-4f15-9884-8ead0ba53f18</guid><dc:creator>bscdb</dc:creator><description>&lt;p&gt;Hey Hakon, I have already tried using&amp;nbsp;&lt;span&gt;APP_UART_TX_EMPTY. I&amp;#39;m using SDK 15.2 &amp;amp; a combination of HID keyboard &amp;amp; Peripheral UART example. When I use&amp;nbsp;APP_UART_TX_EMPTY in uart error handler, the bluetooth connection gets affected so that&amp;#39;s why I removed it. Do you know why this happens?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Align UART transmission/reception with GPIO pin signaling low/high</title><link>https://devzone.nordicsemi.com/thread/186917?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 10:41:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e170512-29df-4e7f-b9ea-94b4397ebc96</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]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() &amp;amp; app_uart_get()[/quote]
&lt;p&gt;Try setting the signal inactive in the uart event handler, upon event &amp;quot;APP_UART_TX_EMPTY&amp;quot;. This should align the pin with the UART transmission.&lt;/p&gt;
[quote user=""](B) After transmitting HID output report, pull GPIO pin high[/quote]
&lt;p&gt;If I understand your scenarios correctly (and please; correct me if I am mistaken), you want to set the pin again after transmitting a given data stream. This would then be equal to your first scenario.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>