<?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>UART on nrf9160dk</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/54395/uart-on-nrf9160dk</link><description>Hello, 
 I am using UART1 to communicate with sensor. It is working fine. I can receive the data. Now I want to modify this data. When I use strcpy() function, it works properly. But when I use functions like strchr(), there is error. I will paste the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 20 Nov 2019 13:28:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/54395/uart-on-nrf9160dk" /><item><title>RE: UART on nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/221093?ContentTypeID=1</link><pubDate>Wed, 20 Nov 2019 13:28:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f8e9f31-8284-4c29-aac1-fa2a821e2f2e</guid><dc:creator>Jagruti</dc:creator><description>&lt;p&gt;Yes you were right. The hard fault was because of&amp;nbsp;&lt;span&gt;FIND_AND_NUL macro. I found the solution for that. Now it is working properly. I can separate all the data continuously. Thank you so much for your help.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART on nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/221008?ContentTypeID=1</link><pubDate>Wed, 20 Nov 2019 10:08:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60cbeb4a-88aa-459c-b0fb-7da14175caa7</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;The FIND_AND_NUL macro does not look very robust, and seems error prone.&lt;br /&gt;If the character is not found by strchr(), strchr() returns a null pointer. And then this macro starts to do pointer operation on a NULL pointer. Maybe you could create a function instead, that is able to handle strchr() returning NULL&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART on nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/220993?ContentTypeID=1</link><pubDate>Wed, 20 Nov 2019 09:29:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05b7f4aa-bd54-4988-b86f-2d04796d60d4</guid><dc:creator>Jagruti</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I observed one more thing. when I perform strchr() operation on the string which is obtained by performing strchr() operation on the received data by UART, there is hard fault. Operation is performed once then hard fault comes. What is the solution for this?&lt;/p&gt;
&lt;p&gt;Code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&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;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

static struct device *uart;
#define UART_BUF_SIZE 256
static u8_t data_array[UART_BUF_SIZE];
static u8_t index = 0;

#define FIND_AND_NUL(s, p, c) ( \
   (p) = strchr(s, c), \
   *(p) = &amp;#39;\0&amp;#39;, \
   ++(p), \
   (p))


void uart_cb(struct device *uart)
{
//    static u8_t data_array[UART_BUF_SIZE];
//    static u8_t index = 0;
	
	uart_irq_update(uart);
	
	if (uart_irq_rx_ready(uart)) {
		
		int data_length;

		data_length = uart_fifo_read(uart, &amp;amp;data_array[index],
					     UART_BUF_SIZE-index);
		index += data_length;
		

		if (index &amp;gt; 0) {
			
			if ((index == UART_BUF_SIZE) ||
			   (data_array[index - 1] == &amp;#39;\n&amp;#39;) ||
			   (data_array[index - 1] == &amp;#39;\r&amp;#39;)) {
				//printk(&amp;quot;index: %d \n&amp;quot;,index);
				printk(&amp;quot;%s&amp;quot;, data_array);
				
//				char dest[strlen(data_array)];
//				strcpy(dest, data_array);
//				printk(&amp;quot;%s&amp;quot;, dest);
				
                const char ch = &amp;#39;,&amp;#39;;
				char *ret;
				ret = strchr(data_array, ch);
				if(ret != NULL){
				printk(&amp;quot;%s&amp;quot;, ret);
				}

                char *ret1;
                const char ch1 = &amp;#39;A&amp;#39;;
                ret1 = strchr(ret, ch1);
                if(ret1 != NULL){
                printk(&amp;quot;%s&amp;quot;, ret1);
                }


				
				index = 0;
				memset(data_array, 0, sizeof(data_array));
			}
		}
	}

}

int init_uart(void)
{
	uart = device_get_binding(&amp;quot;UART_1&amp;quot;);

	uart_irq_callback_set(uart, uart_cb);
	uart_irq_rx_enable(uart);
        printk(&amp;quot;UART sample start!\n&amp;quot;);

	return 0;
}
void main(void)
{
        init_uart();
	
	while (1) {
		k_cpu_idle();

		}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Output:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;UART sample start!
A,4845.1462,N,00220.3119,E,2.06,315.88,201119,,,A*6E
Exception occurred in Secure State
***** HARD FAULT *****
  Fault escalation (see below)
***** BUS FAULT *****
  Precise data bus error
  BFAR Address: 0x50008120
***** Hardware exception *****
Current thread ID = 0x200200b4
Faulting instruction address = 0xe79a
Fatal fault in ISR! Spinning...
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART on nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/220929?ContentTypeID=1</link><pubDate>Tue, 19 Nov 2019 17:09:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b42e6906-e76c-46f3-8c51-3674e5dcec6e</guid><dc:creator>Jagruti</dc:creator><description>&lt;p&gt;prj.conf&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_SERIAL=y
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_UART_1_NRF_UARTE=y
CONFIG_BSD_LIBRARY_TRACE_ENABLED=n&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;nrf9160_pca10090ns.dts_compiled&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/dts-v1/;

/ {
	#address-cells = &amp;lt; 0x01 &amp;gt;;
	#size-cells = &amp;lt; 0x01 &amp;gt;;
	model = &amp;quot;Nordic PCA10090 Dev Kit&amp;quot;;
	compatible = &amp;quot;nordic,pca10090-dk&amp;quot;, &amp;quot;nordic,nrf9160-sica&amp;quot;, &amp;quot;nordic,nrf9160&amp;quot;;



			uart1: uart@9000 {
				compatible = &amp;quot;nordic,nrf-uarte&amp;quot;;
				reg = &amp;lt; 0x9000 0x1000 &amp;gt;;
				interrupts = &amp;lt; 0x09 0x01 &amp;gt;;
				status = &amp;quot;ok&amp;quot;;
				label = &amp;quot;UART_1&amp;quot;;
				current-speed = &amp;lt; 0x1c200 &amp;gt;;
				tx-pin = &amp;lt; 0x01 &amp;gt;;
				rx-pin = &amp;lt; 0x00 &amp;gt;;
				rts-pin = &amp;lt; 0x0e &amp;gt;;
				cts-pin = &amp;lt; 0x0f &amp;gt;;
			};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;There is no overlay file. All definitions are in dts_compiled and I am compiling for&amp;nbsp;&lt;span&gt;nrf9160_pca10090ns.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Your given code is working. I can receive the data continuously. when I remove&amp;nbsp;if(ret != NULL) from the code, I get data once and then there is hard fault. So what is the condition to remove the hard fault from my code. I tried various things but it is not working. I get the output once then there is hard fault.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART on nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/220926?ContentTypeID=1</link><pubDate>Tue, 19 Nov 2019 16:49:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0cb375ac-276c-48b2-96fc-4ee27d9fcaad</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;How does your prj.conf file looks like? Are you using an overlay ? Are you compiling for nrf9160_pca10090ns or nrf9160_pca10090 ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART on nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/220872?ContentTypeID=1</link><pubDate>Tue, 19 Nov 2019 13:56:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:354f8522-e344-4a22-a5d9-9833bb8a2749</guid><dc:creator>Jagruti</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thank you very much for the reply. The code you sent is working.&lt;/p&gt;
&lt;p&gt;Actually I am trying to separate the GNSS data received by UART. Now I can separte the data once then the hard fault comes. What is the condition to be set so that the hard fault doesn&amp;#39;t come and I can separate the data continuously?&lt;/p&gt;
&lt;p&gt;Code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#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;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

#define UART_BUF_SIZE 1024

#define FIND_AND_NUL(s, p, c) ( \
   (p) = strchr(s, c), \
   *(p) = &amp;#39;\0&amp;#39;, \
   ++(p), \
   (p))


void uart_cb(struct device *uart)
{
    static u8_t data_array[UART_BUF_SIZE];
    static u8_t index = 0;
	
	uart_irq_update(uart);
	
	if (uart_irq_rx_ready(uart)) {
		
		int data_length;

		data_length = uart_fifo_read(uart, &amp;amp;data_array[index],
					     UART_BUF_SIZE-index);
		index += data_length;
		

		if (index &amp;gt; 0) {
			
			if ((index == UART_BUF_SIZE) ||
			   (data_array[index - 1] == &amp;#39;\n&amp;#39;) ||
			   (data_array[index - 1] == &amp;#39;\r&amp;#39;)) {
				//printk(&amp;quot;index: %d \n&amp;quot;,index);
				printk(&amp;quot;%s&amp;quot;, data_array);
				
//				char dest[strlen(data_array)];
//				strcpy(dest, data_array);
//				printk(&amp;quot;%s&amp;quot;, dest);
				
//              const char ch = &amp;#39;,&amp;#39;;
//				char *ret;
//				ret = strchr(data_array, ch);
//				if(ret != NULL){
//				printk(&amp;quot;%s&amp;quot;, ret);
//				}
                                
                                char* Message_id = data_array;
                                char* Time = FIND_AND_NUL(data_array, Time, &amp;#39;,&amp;#39;);
                                char* Data_Valid =FIND_AND_NUL(Time, Data_Valid, &amp;#39;,&amp;#39;);
                                char* Raw_Latitude = FIND_AND_NUL(Data_Valid, Raw_Latitude, &amp;#39;,&amp;#39;);
                                char* N_S = FIND_AND_NUL(Raw_Latitude, N_S, &amp;#39;,&amp;#39;);
                                char* Raw_Longitude = FIND_AND_NUL(N_S, Raw_Longitude, &amp;#39;,&amp;#39;);
                                char* E_W = FIND_AND_NUL(Raw_Longitude, E_W, &amp;#39;,&amp;#39;);
                                char* Speed = FIND_AND_NUL(E_W, Speed, &amp;#39;,&amp;#39;);
                                char* COG = FIND_AND_NUL(Speed, COG, &amp;#39;,&amp;#39;);
                                char* Date = FIND_AND_NUL(COG, Date, &amp;#39;,&amp;#39;);
                                char* Magnetic_Variation = FIND_AND_NUL(Date, Magnetic_Variation, &amp;#39;,&amp;#39;);
                                char* M_E_W = FIND_AND_NUL(Magnetic_Variation, M_E_W, &amp;#39;,&amp;#39;);
                                char* Checksum = FIND_AND_NUL(M_E_W, Checksum, &amp;#39;,&amp;#39;);

                                printk(&amp;quot;The Message ID is : %s\n&amp;quot;, Message_id);
                                printk(&amp;quot;The Time is : %s\n&amp;quot;, Time);                              
                                printk(&amp;quot;The data valid is : %s\n&amp;quot;, Data_Valid);
                                printk(&amp;quot;The Latitude is : %s\n&amp;quot;, Raw_Latitude);
                                printk(&amp;quot;The N_S is : %s\n&amp;quot;, N_S);
                                printk(&amp;quot;The Longitude is : %s\n&amp;quot;, Raw_Longitude);
                                printk(&amp;quot;The E_W is : %s\n&amp;quot;, E_W);
                                printk(&amp;quot;The Speed is : %s\n&amp;quot;, Speed);
                                printk(&amp;quot;The COG is : %s\n&amp;quot;, COG);
                                printk(&amp;quot;The Date is : %s\n&amp;quot;, Date);
                                printk(&amp;quot;The Magnetic_Variation is : %s\n&amp;quot;, Magnetic_Variation);
                                printk(&amp;quot;The M_E_W is : %s\n&amp;quot;, M_E_W);
                                printk(&amp;quot;The Checksum is : %s\n&amp;quot;, Checksum);
				
				index = 0;
				memset(data_array, 0, sizeof(data_array));
			}
		}
	}

}

void main(void)
{
        
	struct device *uart = device_get_binding(&amp;quot;UART_1&amp;quot;);

	uart_irq_callback_set(uart, uart_cb);
	uart_irq_rx_enable(uart);
	printk(&amp;quot;UART sample start!\n&amp;quot;);
	while (1) {
		k_cpu_idle();

		}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Output:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;UART sample start!
The Message ID is : $GPRMC
The Time is : 132920.077
The data valid is : V
The Latitude is : 
The N_S is : 
The Longitude is : 
The E_W is : 
The Speed is : 0.00
The COG is : 0.00
The Date is : 191119
The Magnetic_Variation is : 
The M_E_W is : 
The Checksum is : N*46

Exception occurred in Secure State
***** HARD FAULT *****
  Fault escalation (see below)
***** BUS FAULT *****
  Precise data bus error
  BFAR Address: 0x50008120
***** Hardware exception *****
Current thread ID = 0x200200b0
Faulting instruction address = 0xc538
Fatal fault in ISR! Spinning...&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART on nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/220686?ContentTypeID=1</link><pubDate>Mon, 18 Nov 2019 21:28:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b066eb4-8614-4be7-885b-176b469169c6</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This seems to work fine when I test here:&lt;/p&gt;
&lt;p&gt;main.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#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;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

#define UART_BUF_SIZE 1024

void uart_cb(struct device *uart)
{
	static u8_t data_array[UART_BUF_SIZE];
    static u8_t index = 0;
	
	uart_irq_update(uart);
	
	if (uart_irq_rx_ready(uart)) {
		
		int data_length;

		data_length = uart_fifo_read(uart, &amp;amp;data_array[index],
					     UART_BUF_SIZE-index);
		index += data_length;
		

		if (index &amp;gt; 0) {
			
			if ((index == UART_BUF_SIZE) ||
			   (data_array[index - 1] == &amp;#39;\n&amp;#39;) ||
			   (data_array[index - 1] == &amp;#39;\r&amp;#39;)) {
				//printk(&amp;quot;index: %d \n&amp;quot;,index);
				printk(&amp;quot;%s&amp;quot;, data_array);
				
				char dest[strlen(data_array)];
				strcpy(dest, data_array);
				printk(&amp;quot;%s&amp;quot;, dest);
				const char ch = &amp;#39;,&amp;#39;;
				char *ret;
				ret = strchr(data_array, ch);
				
				if(ret != NULL){
				printk(&amp;quot;%s&amp;quot;, ret);
				}

				index = 0;
				memset(data_array, 0, sizeof(data_array));
			}
		}
	}

}

void main(void)
{
        
	struct device *uart = device_get_binding(&amp;quot;UART_1&amp;quot;);

	uart_irq_callback_set(uart, uart_cb);
	uart_irq_rx_enable(uart);
	printk(&amp;quot;UART sample start!\n&amp;quot;);
	while (1) {
		k_cpu_idle();
                
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;prj.conf&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#
# General config
#CONFIG_NEWLIB_LIBC=y
CONFIG_ASSERT=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_REBOOT=y

# Network
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y

# BSD library
CONFIG_BSD_LIBRARY=y

# Stacks and heaps
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_HEAP_MEM_POOL_SIZE=16384



CONFIG_UART_1_NRF_UARTE=y
CONFIG_UART_1_NRF_FLOW_CONTROL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;nrf9160_pca10090ns.overlay&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;uart1 {
	current-speed = &amp;lt;115200&amp;gt;;
	status = &amp;quot;okay&amp;quot;;
	tx-pin = &amp;lt;1&amp;gt;;
	rx-pin = &amp;lt;0&amp;gt;;
	rts-pin = &amp;lt;14&amp;gt;;
	cts-pin = &amp;lt;15&amp;gt;;
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Building and flashing with:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;west build -b nrf9160_pca10090ns -d my_build_folder -p &amp;amp;&amp;amp; west flash -d my_build_folder&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;with nrfjprog -v&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;C:\ncs\nrf\samples\nrf9160\uart&amp;gt;nrfjprog -v
nrfjprog version: 10.5.0
JLinkARM.dll version: 6.54c&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If this does not work for you, let me know what NCS tag/commit/branch you are using.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>