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

UART on nrf 9160 for nrf 52840

Hello  Nordic Support Team

I need desperate help to get my proof of concept working. I have been able to prove that the applicational concepts work on the nRF52840 and now it is only up to proving that the nrf9160 can receive an SMS, request the data from the nrf52840, and send the data via SMS back.  I have no background in electronics so it is very difficult or impossible for me to understand some of the examples. Searching for weeks I stumble upon this example which is very close to what I need and can understand but it is not working for the nrf52840. The following statement "printk("%s", data_array);" does not function.   Can you make it to work for the nrf52840. I prepared to pay for it. Just let me know the costs.  Here are my findings: 

/

/* Data received by the nrf 52840 from the nrf 9160  when the 
print statement is placed in this part of the program 
                       printk("%s",data_array);
		       index = 0;
		       memset(data_array, 0, sizeof(data_array));
The nrf 9150 use the following progam to send the data

*/ 
*** Booting Zephyr OS build v2.4.99-ncs1  ***
UART sample start!
.** Booting Zephyr OS build v2.4.99-ncs2  ***



Flash regions		Domain		Permissions



00 00 000000 0x08000 	Secure		rwxl



01 31 x00 0x100000 	Non-Secure	rwxl







Non-sr lable region 0 placed in flash region 0 with size 32.







ÿÿ[02]I[19]}U[05]IQ[15][01][02][02][02][02][02][02][02][02][02]•ÕÉ•-%Aº[02]I[19]}Q]%5[01][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-Â[02]I[19]}MA%5[01][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-Ê[02]I[19]}Q%5[15]I[01][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…‚[02]I[19]}Q%5[15]I[01][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…Š[02]I[19]}Q%5[15]I[01][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…’[02]I[19]}M[05][05][11]

[01][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…š[02]I[19]}A]5[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…¢[02]I[19]}A]5[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…ª[02]I[19]}A]5[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…²[02]I[19]}A]5[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…º[02]I[19]}][11]Q[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…Â[02]I[19]}%A

[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…Ê[02]I[19]}Y5

[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-‰‚[02]I[19]}[19]AU[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-‰Š[02]I[19]}[15][1D]U[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-‘’[02]I[19]}[15][1D]U[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-™š[02]I[19]}[11]AA%

[01][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-‰¢[02]I[19]}I[15][1D]U1[05]Q=IM[01][02][02][02][02]½¹M•ÕÉ•=-‰ª[02]I[19]}[1D]A%=Q[15][01][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-A5M¥µ…•…ÑÁ:[05]¥[02]M5MA…ÑÁŠ‚²*A5Mɕ͕ÑÙ•Ñ½É…ÑÁ‘‘A5É•Á…ɕѽ©ÕµÁѽ9½¹M•ÕÉ•¥µ…•*** Booting Zephyr OS build v2.4.99-ncs2  ***



ZT01201535554321



ÿ'SSS[13]Hø7SSS[13]HøZT01201535554321



ZT01201535554321



ZT01201535554321



Þ˜NMSS[13]HøZT01201535554321



ZT01201535554321



¯T0120153555432

þLæMSS[13]Høÿü’‚Šªšªªª¢š’Šþþ–ͪªª¢š’Šþ

/* The following code is used to out the above result  if the printk statement
is not a comment. The current version does not print an results with the printk("%s", data_array);  statement 
at the location after "if ((index == UART_BUF_SIZE) ||
			   (data_array[index - 1] == '\n') ||
			   (data_array[index - 1] == '\r')) "*/
#include <zephyr.h>
#include <sys/printk.h>
#include <drivers/uart.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define UART_BUF_SIZE 1024

void uart_cb(struct device *uart)
{
	static uint8_t data_array[UART_BUF_SIZE];
    static uint8_t index = 0;
	
	uart_irq_update(uart);
	
	if (uart_irq_rx_ready(uart)) {
		
		int data_length;

		data_length = uart_fifo_read(uart, &data_array[index],
					     UART_BUF_SIZE-index);
		index += data_length;
		
                
		if (index > 0) {
                 // printk("Datalength = %d", data_length);
			// printk("%s", data_array);
			if ((index == UART_BUF_SIZE) ||
			   (data_array[index - 1] == '\n') ||
			   (data_array[index - 1] == '\r')) {
                            //printk("index: %c \n",data_array[index - 1]);
				// printk("index: %d \n",index);
				printk("%s", data_array);
				
				/*char dest[strlen(data_array)];
				strcpy(dest, data_array);
				printk("%s", dest);
				const char ch = ',';
				char *ret;
				ret = strchr(data_array, ch);
				
				if(ret != NULL){
				printk("%s", ret);*/
				}
                               
			}


                       // printk("%s",data_array);
		       index = 0;
		       memset(data_array, 0, sizeof(data_array));

		}
	}
  
  


void main(void)
{
        
	struct device *uart = device_get_binding("UART_0");

	uart_irq_callback_set(uart, uart_cb);
	uart_irq_rx_enable(uart);
	printk("UART sample start!\n");
	while (1) {
		k_cpu_idle();
                
	}
}
 
/* prj file settings */
CONFIG_SERIAL=y
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_UART_INTERRUPT_DRIVEN=y

#
# 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

/* Code on the nrf 9160  to transmit the data */

include <zephyr.h>
#include <sys/printk.h>

void main(void)
{         
   char message[]="ZT01201535554321\n"; 
     /* for(int i=0; i <sizeof(message); i++)
          {     
	  printk("%c",message[i]);
         // k_sleep(K_MSEC(200));
        }
        printk("\n"); */
 for(int i=0; i < 20; i++)
 {
      printk("%s",message);
      k_sleep(K_MSEC(200));
  }     
}

Parents
  • Hi!

    I can't do it for you but I'm happy to help you realize your application. 

    You are trying to print the whole array as a string, which doesn't work in C. The program will end up printing out the address of the array, instead of the contents, which is why the output is gibberish. To print out the contents of an array, you need to iterate over each element and print out each individual element.

    Helpful pages to understand more about Arrays are Basic Arrays and  Program to print array in C.

    Good luck and please let me know if you have any follow-up questions!

    Best regards,

    Heidi

  • Hi 

    I am not asking you to build my application but to make a program built by a nordic support member named  Sigurd and found in the devzone to work. The support request and program can be found at this link devzone.nordicsemi.com/.../uart-on-nrf9160dk The c statements are not mine but those of Sigurd. So if the problem is about basic understanding of arrays then please get in touch with Sigurd to fix it because I doubt that I can obtain a better understanding of arrays in C through your suggested links than Sigurd. 

Reply
  • Hi 

    I am not asking you to build my application but to make a program built by a nordic support member named  Sigurd and found in the devzone to work. The support request and program can be found at this link devzone.nordicsemi.com/.../uart-on-nrf9160dk The c statements are not mine but those of Sigurd. So if the problem is about basic understanding of arrays then please get in touch with Sigurd to fix it because I doubt that I can obtain a better understanding of arrays in C through your suggested links than Sigurd. 

Children
Related