<?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>How can I send Data from nRF9160 to external module using UART?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/54099/how-can-i-send-data-from-nrf9160-to-external-module-using-uart</link><description>Hi all 
 I am able to do start loopback using the example of UART. 
 But how to send data to external modules ( like ESP32) via UART from nRF9160. 
 I tried this example Thread And also This its working fine and compile also but not send data on UART</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 13 Nov 2019 09:47:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/54099/how-can-i-send-data-from-nrf9160-to-external-module-using-uart" /><item><title>RE: How can I send Data from nRF9160 to external module using UART?</title><link>https://devzone.nordicsemi.com/thread/219851?ContentTypeID=1</link><pubDate>Wed, 13 Nov 2019 09:47:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43608df1-e326-43ba-b96e-5f15bc3f74ec</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;[quote user="jaydip kavaiya"][/quote]&lt;/p&gt;
&lt;p&gt;Ok P0.10 and P0.11 already used in first UART.&lt;/p&gt;
&lt;p&gt;Can you tell me what are pins safe for second UART like?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;All unused GPIOs are safe to use, but on the DK, there are some pins that overlap with others, and are not routed out on the pin list.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the documentation on GPIOs:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ug_nrf91_dk/UG/nrf91_DK/if_connector.html?cp=2_0_4_3_5"&gt;https://infocenter.nordicsemi.com/topic/ug_nrf91_dk/UG/nrf91_DK/if_connector.html?cp=2_0_4_3_5&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Try to use P0.12 and P0.13 for the next uart.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;[quote user="jaydip kavaiya"][/quote]&lt;/p&gt;
&lt;p&gt;in this function on [ uart_buf ] received both TX and RX string data&lt;/p&gt;
&lt;p&gt;how can i received only RX data.&lt;/p&gt;
&lt;p&gt;Right now i am receiving like A,T,+,C,M,G,F,=,1,\r,\n and O,K also&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Are you certain that the external module isn&amp;#39;t echo&amp;#39;ing back the command with the&amp;nbsp;status? you can&amp;nbsp;use standard string functions to delimit the string. I would recommend reading up on the standard functions provided in string.h:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://en.wikibooks.org/wiki/C_Programming/String_manipulation"&gt;https://en.wikibooks.org/wiki/C_Programming/String_manipulation&lt;/a&gt;&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: How can I send Data from nRF9160 to external module using UART?</title><link>https://devzone.nordicsemi.com/thread/219793?ContentTypeID=1</link><pubDate>Wed, 13 Nov 2019 05:43:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65819a9e-dbac-4d5b-b147-5252b9f4939b</guid><dc:creator>jaydip kavaiya</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Ok P0.10 and P0.11 already used in first UART.&lt;/p&gt;
&lt;p&gt;Can you tell me what are pins safe for second UART like?&lt;/p&gt;
&lt;p&gt;And for 2nd Query&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is my code&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;misc/printk.h&amp;gt;
#include &amp;lt;uart.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

static u8_t uart_buf[1024];
static K_FIFO_DEFINE(fifo_uart_tx_data);
static K_FIFO_DEFINE(fifo_uart_rx_data);
struct uart_data_t {
	void  *fifo_reserved;
	u8_t    data[1024];
	u16_t   len;
};

void uart_sendCOM(struct device *x,  u8_t *Cont)
{
	       
         u16_t len = strlen(Cont); 
         uart_fifo_fill(x, Cont,len );
         uart_irq_tx_enable(x);
         
    
}
void uart_cb(struct device *x)
{
	uart_irq_update(x);
	int data_length = 0;

	if (uart_irq_rx_ready(x)) {
                data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
		uart_buf[data_length] = 0;
	}
	printk(&amp;quot;%s&amp;quot;, uart_buf);

       	if (uart_irq_tx_ready(x)) {
               
        	struct uart_data_t *buf =
			k_fifo_get(&amp;amp;fifo_uart_tx_data, K_NO_WAIT);
		u16_t written = 0;

		/* Nothing in the FIFO, nothing to send */
		if (!buf) {
			uart_irq_tx_disable(x);
			return;
		}

		while (buf-&amp;gt;len &amp;gt; written) {
			written += uart_fifo_fill(x,
						  &amp;amp;buf-&amp;gt;data[written],
						  buf-&amp;gt;len - written);
		}

		while (!uart_irq_tx_complete(x)) {
			/* Wait for the last byte to get
			 * shifted out of the module
			 */
		}

		if (k_fifo_is_empty(&amp;amp;fifo_uart_tx_data)) {
			uart_irq_tx_disable(x);
		}

		k_free(buf);
	
		
	}

       
}

void main(void)
{
	
        struct device *uart1 = device_get_binding(&amp;quot;UART_1&amp;quot;);
       
        uart_irq_rx_enable(uart1);
        uart_irq_callback_set(uart1, uart_cb);
        k_sleep(3000);
        uart_sendCOM(uart1,&amp;quot;AT+CMGF=1\r\n&amp;quot;);
        k_sleep(3000);
        uart_sendCOM(uart1,&amp;quot;AT+CMGS=\&amp;quot;xxxxxxxxxx\&amp;quot;\r\n&amp;quot;); //Mobile no. 9xxxxxxxxx
        k_sleep(3000);
        uart_sendCOM(uart1,&amp;quot;\rCall and SMS both\r\n&amp;quot;);
        k_sleep(3000);
        uart_sendCOM(uart1,&amp;quot;\x1A&amp;quot;);
        k_sleep(3000);
        
        
        while(1);

}
        &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So in This code&amp;nbsp;&lt;/p&gt;
&lt;p&gt;if (uart_irq_rx_ready(x)) {&lt;br /&gt; data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));&lt;br /&gt; uart_buf[data_length] = 0;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;in this function on [ uart_buf ] received both TX and RX string data&lt;/p&gt;
&lt;p&gt;how can i received only RX data.&lt;/p&gt;
&lt;p&gt;Right now i am receiving like A,T,+,C,M,G,F,=,1,\r,\n and O,K also&lt;/p&gt;
&lt;p&gt;I only need O, K so that is an issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I send Data from nRF9160 to external module using UART?</title><link>https://devzone.nordicsemi.com/thread/219697?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 13:58:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c574fae-416f-425f-b8d4-a8cb8714591f</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;[quote user="jaydip kavaiya"][/quote]&lt;/p&gt;
&lt;p&gt;Right now I am able to use UART1 in P0.10 and P0.11 for GSM&amp;nbsp;&lt;/p&gt;
&lt;p&gt;and Now How can I use the second UART for ESP32 so what are pins and which UART I use?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You need to use one UART for each device. The nRF9160 has 3 UARTs, so you can enable another one.&lt;/p&gt;
&lt;p&gt;Its the same procedure as enabling other UART.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Note: CONFIG_BSD_LIBRARY_TRACE_ENABLED should be set to &amp;quot;n&amp;quot; if you plan to use UART1 for the application.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;[quote user="jaydip kavaiya"][/quote]&lt;/p&gt;
&lt;p&gt;Right now I am getting both string TX and RX in [&amp;nbsp;&lt;span&gt;uart_buf&lt;/span&gt;&amp;nbsp;] function I want only RX string Data&lt;/p&gt;
&lt;p&gt;how can I neglect TX data in this array?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I do not understand. Are you reusing the same buffer for transmitting and receiving? Could you post your code?&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: How can I send Data from nRF9160 to external module using UART?</title><link>https://devzone.nordicsemi.com/thread/219580?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 06:01:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:99e23fee-ed30-4dae-9686-9a5e2c4c7807</guid><dc:creator>jaydip kavaiya</dc:creator><description>&lt;p&gt;Hi Hakon Alseth&lt;/p&gt;
&lt;p&gt;Thanks for your kind response&lt;/p&gt;
&lt;p&gt;[1] In Which function I get only RX response string (Data)? like I send AT get in only OK Not AT + OK both.&lt;/p&gt;
&lt;p&gt;Right now I am getting both string TX and RX in [&amp;nbsp;&lt;span&gt;uart_buf&lt;/span&gt;&amp;nbsp;] function I want only RX string Data&lt;/p&gt;
&lt;p&gt;how can I neglect TX data in this array?&lt;/p&gt;
&lt;p&gt;[2] I meant to say how can I use both UART for 2 external modules like 1st is GSM and 2nd is ESP32&lt;/p&gt;
&lt;p&gt;Right now I am able to use UART1 in P0.10 and P0.11 for GSM&amp;nbsp;&lt;/p&gt;
&lt;p&gt;and Now How can I use the second UART for ESP32 so what are pins and which UART I use?&lt;/p&gt;
&lt;p&gt;Because I use Both UART same time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I send Data from nRF9160 to external module using UART?</title><link>https://devzone.nordicsemi.com/thread/219470?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2019 13:06:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f5f8d9f-243a-4789-b5b5-0b2da8b4cb92</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;[quote user="jaydip kavaiya"][/quote]&lt;/p&gt;
&lt;p&gt;When I receive read data in this&amp;nbsp;uart_fifo_read(x, uart_buf, sizeof(uart_buf)) function and in uart_buf received both data&lt;/p&gt;
&lt;p&gt;like A, T,\r,\n and then OK so how can I get only received data like ok.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I do not understand.&amp;nbsp;Can you elaborate on what the issue is? Do you want to do string compare on your received data?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user="jaydip kavaiya"]2. And How can I use uart2 for another second module and what are pins of it[/quote]
&lt;p&gt;Its the exact same procedure, where you define uart2 in your overlay file, and set the wanted GPIOs.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s&amp;nbsp;a thread where the configs are posted:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/45166/nrf9160-at_client-sample-default-uart-port/177737#177737"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/45166/nrf9160-at_client-sample-default-uart-port/177737#177737&lt;/a&gt;&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: How can I send Data from nRF9160 to external module using UART?</title><link>https://devzone.nordicsemi.com/thread/219467?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2019 12:52:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2aa4d3c-7e93-4cad-ae0a-73451862d7c8</guid><dc:creator>jaydip kavaiya</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for your Valuable Replay now I am able to send data to the external module.&lt;/p&gt;
&lt;p&gt;There are 2 things I changed [1] rename file&amp;nbsp;nrf9160_pca10090.overlay to&amp;nbsp;nrf9160_pca10090ns.overlay&lt;/p&gt;
&lt;p&gt;and [2] also changes pin no. what you suggest like P0.10 as TX and P0.11 as RX so&amp;nbsp;That&amp;#39;s Work Thanks&lt;/p&gt;
&lt;p&gt;I need a suggestion for 2 things&lt;/p&gt;
&lt;p&gt;1. When I receive read data in this&amp;nbsp;uart_fifo_read(x, uart_buf, sizeof(uart_buf)) function and in uart_buf received both data&lt;/p&gt;
&lt;p&gt;like A, T,\r,\n and then OK so how can I get only received data like ok.&lt;/p&gt;
&lt;p&gt;2. And How can I use uart2 for another second module and what are pins of it&lt;/p&gt;
&lt;p&gt;Thanks Again&lt;/p&gt;
&lt;p&gt;Jaydip Kavaiya&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I send Data from nRF9160 to external module using UART?</title><link>https://devzone.nordicsemi.com/thread/218868?ContentTypeID=1</link><pubDate>Wed, 06 Nov 2019 14:40:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:155ac6c6-5e71-4b3a-8836-7deee7d80ab6</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;What pins are you using, and which UARTx are you using? Not all pins are routed to the pin-header on the DK, as they are dedicated for other connections, so a safe choice is to use P0.10 and P0.11 for instance.&lt;/p&gt;
&lt;p&gt;Can you share your source code and .overlay file?&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>