nRF9160: Modem callbacks

The Modem callbacks sample demonstrates how to set up callbacks for Modem library initialization and shutdown calls, using the Modem library integration layer and how to set up a callback for changes to the modem functional mode using the LTE link controller library.

Requirements

The sample supports the following development kit:

Hardware platforms

PCA

Board name

Build target

nRF9160 DK

PCA10090

nrf9160dk_nrf9160

nrf9160dk_nrf9160_ns

The sample is configured to compile and run as a non-secure application on nRF91’s Cortex-M33. Therefore, it automatically includes the Secure Partition Manager that prepares the required peripherals to be available for the application.

You can also configure it to use TF-M instead of Secure Partition Manager.

Overview

The sample performs the following operations:

  1. Registers callbacks during compile time for modem initialization, functional mode changes, and shutdown using the NRF_MODEM_LIB_ON_INIT, LTE_LC_ON_CFUN and NRF_MODEM_LIB_ON_SHUTDOWN macros respectively.

  2. Initializes the Modem library.

  3. Changes functional mode using the lte_lc_func_mode_set() function in the LTE link controller library

  4. Shuts down the Modem library.

This triggers the callbacks for on_modem_init(), on_cfun() and on_modem_shutdown() functions.

Building and running

This sample can be found under samples/nrf9160/modem_callbacks in the nRF Connect SDK folder structure.

The sample is built as a non-secure firmware image for the nrf9160dk_nrf9160_ns build target. Because of this, it automatically includes the Secure Partition Manager. You can also configure it to use TF-M instead of SPM.

See Building and programming an application for information about how to build and program the application.

Testing

After programming the sample to your development kit, complete the following steps to test it:

  1. Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.

  2. Connect to the kit with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.

  3. Power on or reset your nRF9160 DK.

  4. Observe that the sample starts, initializes the modem, changes functional mode and shuts down the modem.

Sample output

The sample shows the following output:

Modem callbacks sample started
Initializing modem library
> Initialized with value 0
Changing functional mode
> Functional mode has changed to 1
Shutting down modem library
> Functional mode has changed to 0
> Shutting down
Bye

Dependencies

This sample uses the following nRF Connect SDK libraries:

It uses the following sdk-nrfxlib library:

In addition, it uses the following sample: