Intermediate
30 min

Navigate the broad landscape of LTE IoT with the utmost confidence using SARA-R510M8S and PIC18F57Q43

Experience seamless IoT with LTE excellence

LTE IoT 5 Click with Curiosity Nano with PIC18F57Q43

Published Feb 13, 2024

Click board™

LTE IoT 5 Click

Dev Board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

Discover the power of limitless connection through our advanced LTE IoT solution. Transforming the way devices communicate, our technology redefines what's possible, enabling IoT experiences that go beyond convention.

A

A

Hardware Overview

How does it work?

LTE IoT 5 Click is based on the SARA-R510M8S, a cellular module that supports LTE Cat M1/Cat NB2 bands with an integrated high-performance standard precision M8 GNSS receiver from u-blox. It comes in a miniature SARA LGA form factor module, a drop-in migration from other u-blox cellular module families. The SARA-R510 series modules provide software-based multi-band configurability, enabling international multi-regional coverage in LTE Cat M1/NB2 radio access technologies, supporting a comprehensive set of 3GPP Rel. 14 features that are relevant for IoT applications with data communications up to 1200 kbit/s. The GNSS RF input of the SARA-R510M8S, designed with 50Ω characteristic impedance and with an internal DC block, is suitable for both active and passive GNSS antennas due to the built-in SAW filter followed by an LNA in front of the integrated high-performing u-Blox M8 concurrent positioning engine. This module requires a power supply of 3.8V. Therefore, the Click board™ incorporates an integrated buck (step-down DC-DC) converter labeled TPS7A7002 by Texas Instruments. This IC can output up to 3A of current, maintaining excellent regulation. Its task is to provide a stable 3.8V power supply capable of mitigating voltage drops at the input

when a high current peak appears (typically at the StartUp of the device). The SARA-R510M8S communicates with MCU using the UART interface with automatic baud rate detection used for module control from the external application host processor that can be conveniently configured through AT commands that u-blox provides. This Click board™ is also USB 2.0 compliant, equipped with the USB type C connector with a maximum 480 Mbit/s data rate available for diagnostic purposes only. The module acts as a USB device and can be connected to any USB host with compatible drivers. Besides two female SMA connectors (for LTE and active GNSS antennas), the LTE IoT 5 Click also has a nano-SIM card slot that provides multiple connections and interface options. The J1 header allows you to access the configurable GPIO and EXT Interrupt pin of the SARA module, while test points labeled from TP1 to TP6 enable easy FW upgrades and testing of the module. The onboard active-low push-button labeled as PWR routed to the AN pin on the mikroBUS™ socket represents the Ignition (Power-On) button, which successful action will be indicated by the STAT LED. If the device is powered up, a LOW pulse with a duration of 1.5s on this pin will power the module down. It is also possible

to power down the module by issuing the AT+CPWROFF command or with a Reset function routed to the RST pin on the mikroBUS™ socket that will cause an abrupt Power-Down (forced Power-Down) by sending an active low input on this pin with the duration of 10s. In addition to the Power LED indicator, this Click board™ has two additional LED indicators: the yellow LED labeled as STAT is used to visually indicate the device's Operational Status and a red LED labeled as TX is used to indicate the Network Status. Customers can future-proof their solutions through over-the-air firmware updates, thanks to the uFOTA client/server solution that utilizes LwM2M, a light and compact protocol ideal for IoT. We have also provided accessible test points directly connected to the TxD and RxD pins for FW upgrade purposes. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.

LTE IoT 5 Click hardware overview image

Features overview

Development board

PIC18F57Q43 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate microcontrollers within the PIC18-Q43 family. Central to its design is the inclusion of the powerful PIC18F57Q43 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive

mechanical user switch, providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI

GPIO), offering extensive connectivity options. Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 1.8V to 5.1V, with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.

PIC18F57Q43 Curiosity Nano double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

48

RAM (Bytes)

8196

You complete me!

Accessories

Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.

Curiosity Nano Base for Click boards accessories 1 image

LTE Flat Rotation Antenna is a versatile choice for boosting the performance of 3G/4G LTE devices. With a wide frequency range of 700-2700MHz, it ensures optimal connectivity on major cellular bands worldwide. This flat antenna features an SMA male connector, making it easy to attach directly to your device or SMA module connector. One of its standout features is its adjustable angle, which can be set in 45⁰ increments (0⁰/45⁰/90⁰), allowing you to fine-tune the antenna's orientation for maximum signal reception. With an impedance of 50Ω and a VSW Ratio of <2.0:1, this antenna ensures a reliable and efficient connection. Its 5dB gain, vertical polarization, and omnidirectional radiation pattern enhance signal strength, making it suitable for various applications. Measuring 196mm in length and 38mm in width, this antenna offers a compact yet effective solution for improving your connectivity. With a maximum input power of 50W, it can handle the demands of various devices.

LTE IoT 5 Click accessories 1 image

GNSS Active External Antenna is a unique multi-band type of antenna coming from u-blox that is the perfect selection for high precision GNSS applications, which require highly accurate location abilities such as RTK. The ANN-MB-00 is a multi-band (L1, L2/E5b/B2I) active GNSS antenna with a 5m cable and SMA connector. The antenna supports GPS, GLONASS, Galileo, and BeiDou and includes a high-performance multi-band RHCP dual-feed patch antenna element, a built-in high-gain LNA with SAW pre-filtering, and a 5 m antenna cable with SMA connector, and is waterproof.

LTE IoT 5 Click accessories 2 image

Used MCU Pins

mikroBUS™ mapper

Power-On
PA0
AN
Reset
PA7
RST
UART RTS
PD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
UART RI
PB0
PWM
UART CTS
PA6
INT
UART TX
PC3
TX
UART RX
PC2
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

LTE IoT 5 Click Schematic schematic

Step by step

Project assembly

Curiosity Nano Base for Click boards front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity Nano with PIC18F57Q43 as your development board.

Curiosity Nano Base for Click boards front image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47Q10 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Curiosity Nano with PICXXX Access MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
PIC18F57Q43 Curiosity MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.

Software Support

Library Description

This library contains API for LTE IoT 5 Click driver.

Key functions:

  • lteiot5_generic_read - LTE IoT 5 data reading function

  • lteiot5_send_cmd - Send command function

  • lteiot5_power_on - LTE IoT 5 power on.

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * @file 
 * @brief LTEIoT6 Click example
 * 
 * # Description
 * This example reads and processes data from LTE IoT 5 clicks.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes driver and wake-up module and sets default configuration for connecting device to network.
 * 
 * ## Application Task  
 * Waits for device to connect to network and then sends SMS to selected phone number.
 * 
 * ## Additional Function
 * - static void lteiot5_clear_app_buf ( void )
 * - static void lteiot5_error_check( err_t error_flag )
 * - static void lteiot5_log_app_buf ( void )
 * - static void lteiot5_check_connection( void )
 * - static err_t lteiot5_rsp_check ( void )
 * - static err_t lteiot5_process ( void )
 * 
 * *note:* 
 * In order for the example to work, 
   user needs to set the phone number and sim apn to which he wants to send an SMS
 * Enter valid data for the following macros: SIM_APN and PHONE_NUMBER_TO_MESSAGE.
 * E.g. 
    SIM_APN "vip.mobile"
    PHONE_NUMBER_TO_MESSAGE "999999999"
 * 
 * @author Luka Filipovic
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "lteiot5.h"

#define APP_OK                              0
#define APP_ERROR_DRIVER                    -1
#define APP_ERROR_OVERFLOW                  -2
#define APP_ERROR_TIMEOUT                   -3

#define RSP_OK                              "OK"
#define RSP_ERROR                           "ERROR"

#define SIM_APN                             ""  // Set valid SIM APN
#define PHONE_NUMBER_TO_MESSAGE             ""  // Set Phone number to message
#define MESSAGE_CONTENT                     "LTE IoT 5 Click"   // Messege content 

#define PROCESS_BUFFER_SIZE                 500

#define WAIT_FOR_CONNECTION                 0
#define CONNECTED_TO_NETWORK                1

static lteiot5_t lteiot5;
static log_t logger;

static char app_buf[ PROCESS_BUFFER_SIZE ]  = { 0 };
static int32_t app_buf_len                  = 0;
static int32_t app_buf_cnt                  = 0;

static uint8_t app_connection_status        = WAIT_FOR_CONNECTION;

static err_t app_error_flag;

/**
 * @brief LTE IoT 5 clearing application buffer.
 * @details This function clears memory of application buffer and reset it's length and counter.
 * @note None.
 */
static void lteiot5_clear_app_buf ( void );

/**
 * @brief LTE IoT 5 data reading function.
 * @details This function reads data from device and concats data to application buffer.
 * 
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 *         @li @c -2 - Application buffer overflow.
 *
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t lteiot5_process ( void );

/**
 * @brief LTE IoT 5 check for errors.
 * @details This function checks for different types of errors and logs them on UART.
 * @note None.
 */
static void lteiot5_error_check( err_t error_flag );

/**
 * @brief LTE IoT 5 logs application buffer.
 * @details This function logs data from application buffer.
 * @note None.
 */
static void lteiot5_log_app_buf ( void );

/**
 * @brief LTE IoT 5 response check.
 * @details This function checks for response and returns the status of response.
 * 
 * @return application status.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t lteiot5_rsp_check ( void );

/**
 * @brief LTE IoT 5 chek connection.
 * @details This function checks connection to the network and 
 *          logs that status to UART.
 * 
 * @note None.
 */
static void lteiot5_check_connection( void );



void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    lteiot5_cfg_t lteiot5_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );
    Delay_ms( 1000 );
    
    // Click initialization.
    lteiot5_cfg_setup( &lteiot5_cfg );
    LTEIOT5_MAP_MIKROBUS( lteiot5_cfg, MIKROBUS_1 );
    err_t init_flag  = lteiot5_init( &lteiot5, &lteiot5_cfg );
    if ( init_flag == UART_ERROR )
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    
    log_info( &logger, " Power on device... " );
    lteiot5_reset( &lteiot5 );
    lteiot5_power_on( &lteiot5 );
    
    lteiot5_send_cmd( &lteiot5, LTEIOT5_CMD_AT );
    Delay_ms( 500 );
    lteiot5_process(  );
    lteiot5_clear_app_buf(  );
    
    //AT
    lteiot5_send_cmd( &lteiot5, LTEIOT5_CMD_AT );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //ATI
    lteiot5_send_cmd( &lteiot5, LTEIOT5_CMD_ATI );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //ATI
    lteiot5_send_cmd( &lteiot5, LTEIOT5_CMD_CGMR );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //CFUN
    lteiot5_send_cmd_with_parameter( &lteiot5, LTEIOT5_CMD_CFUN, "0" );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //COPS
    lteiot5_send_cmd_with_parameter( &lteiot5, LTEIOT5_CMD_COPS, "2" );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //CGDCONT
    lteiot5_set_sim_apn( &lteiot5, SIM_APN );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //URAT
    lteiot5_send_cmd_with_parameter( &lteiot5, LTEIOT5_CMD_URAT, "7" );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //UBANDMASK,
    lteiot5_send_cmd_with_parameter( &lteiot5, LTEIOT5_CMD_UBANDMASK, "0,185473183" );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //CFUN
    lteiot5_send_cmd_with_parameter( &lteiot5, LTEIOT5_CMD_CFUN, "1" );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 1000 );
    
    //CFUN
    lteiot5_send_cmd_with_parameter( &lteiot5, LTEIOT5_CMD_CFUN, "16" );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 5000 );
    
    lteiot5_send_cmd_check( &lteiot5, LTEIOT5_CMD_CFUN );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //COPS
    lteiot5_send_cmd_check( &lteiot5, LTEIOT5_CMD_COPS );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //UANTR
    lteiot5_send_cmd_with_parameter( &lteiot5, LTEIOT5_CMD_UANTR, "0" );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //CEREG
    lteiot5_send_cmd_with_parameter( &lteiot5, LTEIOT5_CMD_CEREG, "2" );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    //CIMI
    lteiot5_send_cmd( &lteiot5, LTEIOT5_CMD_CIMI );
    app_error_flag = lteiot5_rsp_check();
    lteiot5_error_check( app_error_flag );
    Delay_ms( 500 );
    
    app_buf_len = 0;
    app_buf_cnt = 0;
    app_connection_status = WAIT_FOR_CONNECTION;
    log_info( &logger, " Application Task " );
    Delay_ms( 5000 );
}

void application_task ( void )
{  
    if ( app_connection_status == WAIT_FOR_CONNECTION )
    {
        lteiot5_send_cmd_check( &lteiot5, LTEIOT5_CMD_CGATT );
        app_error_flag = lteiot5_rsp_check();
        lteiot5_error_check( app_error_flag );
        Delay_ms( 500 );
        
        lteiot5_send_cmd_check( &lteiot5, LTEIOT5_CMD_CEREG );
        app_error_flag = lteiot5_rsp_check();
        lteiot5_error_check( app_error_flag );
        Delay_ms( 500 );
        
        lteiot5_send_cmd( &lteiot5, LTEIOT5_CMD_CSQ );
        app_error_flag = lteiot5_rsp_check();
        lteiot5_error_check( app_error_flag );
        Delay_ms( 5000 );
    }
    else
    {
        log_info( &logger, "CONNECTED TO NETWORK" );
        
        lteiot5_send_cmd_with_parameter( &lteiot5, "AT+CMGF", "1" );
        app_error_flag = lteiot5_rsp_check();
        lteiot5_error_check( app_error_flag );
        Delay_ms( 3000 );
        
        for( ; ; )
        {   
            log_printf( &logger, "> Sending message to phone number...\r\n" );
            lteiot5_send_text_message( &lteiot5, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
            app_error_flag = lteiot5_rsp_check();
            lteiot5_error_check( app_error_flag );
            Delay_ms( 10000 );
        }
    }
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}

static void lteiot5_clear_app_buf ( void )
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
    app_buf_cnt = 0;
}

static err_t lteiot5_process ( void )
{
    err_t return_flag = APP_ERROR_DRIVER;
    int32_t rx_size;
    char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
    
    rx_size = lteiot5_generic_read( &lteiot5, rx_buff, PROCESS_BUFFER_SIZE );

    if ( rx_size > 0 )
    { 
        int32_t buf_cnt = 0;
        return_flag = APP_OK;

        if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
        {
            lteiot5_clear_app_buf(  );
            return_flag = APP_ERROR_OVERFLOW;
        }
        else
        {
            buf_cnt = app_buf_len;
            app_buf_len += rx_size;
        }

        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ )
        {
            if ( rx_buff[ rx_cnt ] != 0 ) 
            {
                app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buff[ rx_cnt ];
            }
            else
            {
                app_buf_len--;
            }
        }
    } 

    return return_flag;
}

static err_t lteiot5_rsp_check ( void )
{
    uint16_t timeout_cnt = 0;
    uint16_t timeout = 10000;
    
    err_t error_flag = lteiot5_process(  );
    if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
    {
        return error_flag;
    }
    
    while ( ( strstr( app_buf, RSP_OK ) == 0 ) && ( strstr( app_buf, RSP_ERROR ) == 0 ) )
    {
        error_flag = lteiot5_process(  );
        if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
        {
            return error_flag;
        }
        
        timeout_cnt++;
        if ( timeout_cnt > timeout )
        {
            while ( ( strstr( app_buf, RSP_OK ) == 0 ) && ( strstr( app_buf, RSP_ERROR ) == 0 ) )
            {
                lteiot5_send_cmd( &lteiot5, LTEIOT5_CMD_AT );
                lteiot5_process(  );
                Delay_ms( 100 );
            }
            lteiot5_clear_app_buf(  );
            return APP_ERROR_TIMEOUT;
        }
        
        Delay_ms( 1 );
    }
    
    lteiot5_check_connection();
    
    lteiot5_log_app_buf();
    
    log_printf( &logger, "-----------------------------------\r\n" );
    
    return APP_OK;
}

static void lteiot5_error_check( err_t error_flag )
{
    if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
    {
        switch ( error_flag )
        {
            case -2:
                log_error( &logger, " Overflow!" );
                break;
            case -3:
                log_error( &logger, " Timeout!" );
                break;
            default:
                break;
        }
    }
}

static void lteiot5_log_app_buf ( void )
{
    for ( int32_t buf_cnt = 0; buf_cnt < app_buf_len; buf_cnt++ )
    {
        log_printf( &logger, "%c", app_buf[ buf_cnt ] );
    }
    log_printf( &logger, "\r\n" );
    lteiot5_clear_app_buf(  );
}

static void lteiot5_check_connection( void )
{
    #define CONNECTED "+CGATT: 1"
    
    if ( strstr( app_buf, CONNECTED ) != 0 )
    {
        app_connection_status = CONNECTED_TO_NETWORK;
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.