GPS Sample

Last updated on: November 16, 2020

Introduction

The GPS sample sets up the modem GPS on the Icarus board and keeps displaying GPS data (location and satellite information) in a loop.

The GPS Sample can be found in the Nordic nRF9160 Samples

Project configuration

In order to use the modem's GPS module, the sample enables the following settings in the prj.conf file:

CONFIG_BSD_LIBRARY=y
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_HEAP_MEM_POOL_SIZE=2048
CONFIG_MAIN_STACK_SIZE=4096

which enable the libraries that set up the communication with the modem (communication with the modem is done through a socket).

Additionally, the sample enables the following directives:

CONFIG_STDOUT_CONSOLE=y
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

which enable the printing of float numbers and enables logging over serial.

It also disables the networking stack to save memory using the following directives:

CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=n
CONFIG_NET_UDP=n
CONFIG_NET_TCP=n

Code explanation

The sample initializes the modem into GPS mode, sets the modem MAGPIO configuration and turns the modem on by sending the following commands to the modem over an open modem socket:

AT%XSYSTEMMODE=0,0,1,0
AT%XMAGPIO=1,0,0,1,1,1574,1577
AT+CFUN=1

sets the GPS parameters (GNSS fix interval, GNSS fix retry interval and retrieved data format):

NRF_SO_GNSS_FIX_RETRY
NRF_SO_GNSS_FIX_INTERVAL
NRF_SO_GNSS_NMEA_MASK

and finally starts the GPS.

NRF_SO_GNSS_START

All these commands are sent to the modem through the open modem socket.

The GPS data (location and satellite information) is then retrieved from the modem from the socket:

int retval = nrf_recv(fd, gps_data, sizeof(nrf_gnss_data_frame_t), NRF_MSG_DONTWAIT);

and printed in a loop.