Intermediate
20 min

Create a versatile communication solution with a focus on LTE and VoLTE capabilities with ELS62-E and STM32F413ZH

LTE Cat.1bis single antenna module with 2G fallback for European region

LTE Cat.1 2 Click with Nucleo 144 with STM32F413ZH MCU

Published Feb 14, 2024

Click board™

LTE Cat.1 2 Click

Dev. board

Nucleo 144 with STM32F413ZH MCU

Compiler

NECTO Studio

MCU

STM32F413ZH

Unlock seamless and robust communication possibilities with advanced LTE and VoLTE functionalities, revolutionizing the development of smart and connected devices for homes, industries, and remote operations

A

A

Hardware Overview

How does it work?

LTE Cat.1.2 Click (EU) is based on the ELS62-E, a single antenna LTE Cat. 1bis module from Telit. The module supports GSM, GPRS, and EDGE in frequencies of 900 and 1800MHz. It also supports the LTE band in 800, 850, 1800, and 2100MHz frequencies. The module allows you to use SMS as a point-to-point MT and MO, cell broadcast, text, and PDU mode and allows you to use SIM card storage. The SIM card socket is placed below the board. It can achieve a download speed of 10.2Mbps and an upload speed of 5.2Mbps. The ELS62-E also comes with a USB C connector that supports a USB 2.0 standard and is high-speed (480Mbps) and full-speed compliant (12Mbps). The connector is intended for a firmware update of the modem. The ELS62-E supports a digital audio interface (DAI) employed as a pulse code modulation interface (PCM). The PCM interfaces the MAX9860, a 16-bit mono audio voice codec

from Analog Devices. It supports a low-noise microphone input, mono amplifier, automatic microphone gain control and noise gate, and more. The audio codec can output 30mW into a 32Ω earpiece with a microphone connected over the 3.5mm audio jack. As the module uses several different voltages, there is an AP2112K, an LDO from Diodes Incorporated, which supplies the module with the needed 1.8V. There is also a TPS7A7002, an LDO from Texas Instruments, for the required supply of 4.2V. For logic-level translation, this Click™ board uses four SN74LVC1T450 transceivers and one PCA9306 transceiver, all from Texas Instruments. The yellow STAT LED indicates different operating modes of the module, while the blue PWI LED indicates the module's 1.8V power supply. LTE Cat.1.2 Click EU uses a standard UART interface to communicate with the host MCU with commonly used UART RX

and TX pins. It also allows you to use a UART control flow pins RTS and CTS (CTS on pin CS). The UART of the modem can operate at fixed bit rates from 300bps up to 921600bps. Besides the library we provide, you can use an AT set of commands to control the module. The fast shutdown option is left disabled. You can enable it over the R27 resistor and use it over the FSD pin. The audio codec uses a standard 2-wire I2C interface to communicate with the host MCU. It allows you to use the volume control, shutdown mode, and more. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

LTE Cat.1 2 Click hardware overview image

Features overview

Development board

Nucleo-144 with STM32F413ZH MCU board offers an accessible and adaptable avenue for users to explore new ideas and construct prototypes. It allows users to tailor their experience by selecting from a range of performance and power consumption features offered by the STM32 microcontroller. With compatible boards, the

internal or external SMPS dramatically decreases power usage in Run mode. Including the ST Zio connector, expanding ARDUINO Uno V3 connectivity, and ST morpho headers facilitate easy expansion of the Nucleo open development platform. The integrated ST-LINK debugger/programmer enhances convenience by

eliminating the need for a separate probe. Moreover, the board is accompanied by comprehensive free software libraries and examples within the STM32Cube MCU Package, further enhancing its utility and value.

Nucleo 144 with STM32F413ZH MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

1536

Silicon Vendor

STMicroelectronics

Pin count

144

RAM (Bytes)

327680

You complete me!

Accessories

Click Shield for Nucleo-144 comes equipped with four mikroBUS™ sockets, with one in the form of a Shuttle connector, allowing all the Click board™ devices to be interfaced with the STM32 Nucleo-144 board with no effort. This way, MIKROE allows its users to add any functionality from our ever-growing range of Click boards™, such as WiFi, GSM, GPS, Bluetooth, ZigBee, environmental sensors, LEDs, speech recognition, motor control, movement sensors, and many more. Featuring an ARM Cortex-M microcontroller, 144 pins, and Arduino™ compatibility, the STM32 Nucleo-144 board offers limitless possibilities for prototyping and creating diverse applications. These boards are controlled and powered conveniently through a USB connection to program and efficiently debug the Nucleo-144 board out of the box, with an additional USB cable connected to the USB mini port on the board. Simplify your project development with the integrated ST-Link debugger and unleash creativity using the extensive I/O options and expansion capabilities. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the STM32 Nucleo-144 board with our Click Shield for Nucleo-144, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Nucleo-144 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 Cat.1 2 Click accessories 1 image

IPEX-SMA cable is a type of RF (radio frequency) cable assembly. "IPEX" refers to the IPEX connector, a miniature coaxial connector commonly used in small electronic devices. "SMA" stands for SubMiniature Version A and is another coaxial connector commonly used in RF applications. An IPEX-SMA cable assembly has an IPEX connector on one end and an SMA connector on the other, allowing it to connect devices or components that use these specific connectors. These cables are often used in applications like WiFi or cellular antennas, GPS modules, and other RF communication systems where a reliable and low-loss connection is required.

LTE Cat.1 2 Click accessories 2 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
ID SEL
PA13
RST
UART CTS / ID COMM
PA4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Fast Shutdown
PC6
PWM
UART RTS
PF13
INT
UART TX
PA9
TX
UART RX
PA10
RX
I2C Clock
PF1
SCL
I2C Data
PF0
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

LTE Cat.1 2 Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-144 accessories 1 image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 144 with STM32F413ZH MCU as your development board.

Click Shield for Nucleo-144 accessories 1 image hardware assembly
Nucleo 144 with STM32F446ZE MCU front image hardware assembly
Charger 27 Click front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Board mapper by product8 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
STM32F413ZH Nucleo 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

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for LTE Cat.1 2 Click driver.

Key functions:

  • ltecat12_max9860_cfg - LTE Cat.1 2 MAX9860 configuration function.

  • ltecat12_send_cmd - LTE Cat.1 2 send command function.

  • ltecat12_send_sms_pdu - LTE Cat.1 2 send SMS in PDU mode.

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 main.c
 * @brief LTE Cat.1 2 Click Example.
 *
 * # Description
 * Application example shows device capability of connecting to the network and 
 * sending SMS, TCP/UDP messages or calling the selected number using standard "AT" commands. 
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Sets the device configuration for sending SMS, TCP/UDP messages or calling the selected number.
 *
 * ## Application Task
 * Depending on the selected demo example, it sends an SMS message 
 * (in PDU or TXT mode) or a TCP/UDP message or calls the selected number.
 *
 * ## Additional Function
 * - static void ltecat12_clear_app_buf ( void )
 * - static err_t ltecat12_process ( void )
 * - static void ltecat12_error_check( err_t error_flag )
 * - static void ltecat12_log_app_buf ( void )
 * - static err_t ltecat12_rsp_check ( uint8_t *rsp )
 * - static err_t ltecat12_cfg_for_network ( void )
 * - static err_t ltecat12_check_connection ( void )
 * - static err_t ltecat12_cfg_for_example ( void )
 * - static err_t ltecat12_example ( void )
 *
 * @note
 * In order for the examples to work, user needs to set the APN and SMSC (SMS PDU mode only)
 * of entered SIM card as well as the phone number (SMS mode only) to which he wants to send an SMS.
 * Enter valid values for the following macros: SIM_APN, SIM_SMSC and PHONE_NUMBER_TO_MESSAGE.
 * Example:
    SIM_APN "internet"
    SIM_SMSC "+381610401"
    PHONE_NUMBER_TO_MESSAGE "+381659999999"
 *
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "ltecat12.h"
#include "generic_pointer.h"
#include "conversions.h"

// Example selection macros
#define EXAMPLE_TCP_UDP                     0               // Example of sending messages to a TCP/UDP echo server
#define EXAMPLE_SMS                         1               // Example of sending SMS to a phone number
#define EXAMPLE_CALL                        2               // Example of calling selected phone number
#define DEMO_EXAMPLE                        EXAMPLE_TCP_UDP // Example selection macro

// SIM APN config
#define SIM_APN                             "internet"      // Set valid SIM APN

// SMS/CALL example parameters
#define SIM_SMSC                            ""              // Set valid SMS Service Center Address - only in SMS PDU mode
#define PHONE_NUMBER                        ""              // Set Phone number to message or call
#define SMS_MODE                            "1"             // SMS mode: "0" - PDU, "1" - TXT

// TCP/UDP example parameters
#define REMOTE_IP                           "77.46.162.162" // TCP/UDP echo server IP address
#define REMOTE_PORT                         "51111"         // TCP/UDP echo server port

// Message content
#define MESSAGE_CONTENT                     "LTE Cat.1 2 Click board - demo example."

// Application buffer size
#define APP_BUFFER_SIZE                     256
#define PROCESS_BUFFER_SIZE                 256

/**
 * @brief Example states.
 * @details Predefined enum values for application example state.
 */
typedef enum
{
    LTECAT12_CONFIGURE_FOR_NETWORK = 1,
    LTECAT12_WAIT_FOR_CONNECTION,
    LTECAT12_CONFIGURE_FOR_EXAMPLE,
    LTECAT12_EXAMPLE

} ltecat12_example_state_t;

static ltecat12_t ltecat12;
static log_t logger;

/**
 * @brief Application example variables.
 * @details Variables used in application example.
 */
static uint8_t app_buf[ APP_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static err_t error_flag;
static ltecat12_example_state_t example_state;

/**
 * @brief Clearing application buffer.
 * @details This function clears memory of application
 * buffer and reset its length and counter.
 */
static void ltecat12_clear_app_buf ( void );

/**
 * @brief Data reading function.
 * @details This function reads data from device and
 * appends it to the application buffer.
 * @return @li @c  0 - Some data is read.
 *         @li @c -1 - Nothing is read.
 * See #err_t definition for detailed explanation.
 */
static err_t ltecat12_process ( void );

/**
 * @brief Check for errors.
 * @details This function checks for different types of
 * errors and logs them on UART or logs the response if no errors occured.
 * @param[in] error_flag  Error flag to check.
 */
static void ltecat12_error_check( err_t error_flag );

/**
 * @brief Logs application buffer.
 * @details This function logs data from application buffer.
 */
static void ltecat12_log_app_buf ( void );

/**
 * @brief Response check.
 * @details This function checks for response and
 * returns the status of response.
 * @param[in] rsp  Expected response.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 *         @li @c -4 - Unknown error.
 * See #err_t definition for detailed explanation.
 */
static err_t ltecat12_rsp_check ( uint8_t *rsp );

/**
 * @brief Configure device for connection to the network.
 * @details Sends commands to configure and enable
 * connection to the specified network.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 *         @li @c -4 - Unknown error.
 * See #err_t definition for detailed explanation.
 */
static err_t ltecat12_cfg_for_network ( void );

/**
 * @brief Wait for connection signal.
 * @details Wait for connection signal from CREG URC.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 *         @li @c -4 - Unknown error.
 * See #err_t definition for detailed explanation.
 */
static err_t ltecat12_check_connection ( void );

/**
 * @brief Configure device for example.
 * @details Configure device for the specified example.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 *         @li @c -4 - Unknown error.
 * See #err_t definition for detailed explanation.
 */
static err_t ltecat12_cfg_for_example ( void );

/**
 * @brief Execute example.
 * @details This function executes SMS, TCP/UDP or CALL example depending on the DEMO_EXAMPLE macro.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 *         @li @c -4 - Unknown error.
 * See #err_t definition for detailed explanation.
 */
static err_t ltecat12_example( void );

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    ltecat12_cfg_t ltecat12_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 " );

    // Click initialization.
    ltecat12_cfg_setup( &ltecat12_cfg );
    LTECAT12_MAP_MIKROBUS( ltecat12_cfg, MIKROBUS_1 );
    if ( UART_ERROR == ltecat12_init( &ltecat12, &ltecat12_cfg ) )
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );
        for ( ; ; );
    }
    
    ltecat12_process( );
    ltecat12_clear_app_buf( );

    // Restart device
    #define RESTART_DEVICE "1,1"
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_CFUN, RESTART_DEVICE );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_SYSSTART );
    ltecat12_error_check( error_flag );
    
    // Check communication
    ltecat12_send_cmd( &ltecat12, LTECAT12_CMD_AT );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    ltecat12_error_check( error_flag );
    
    log_info( &logger, " Application Task " );
    example_state = LTECAT12_CONFIGURE_FOR_NETWORK;
}

void application_task ( void )
{
    switch ( example_state )
    {
        case LTECAT12_CONFIGURE_FOR_NETWORK:
        {
            if ( LTECAT12_OK == ltecat12_cfg_for_network( ) )
            {
                example_state = LTECAT12_WAIT_FOR_CONNECTION;
            }
            break;
        }
        case LTECAT12_WAIT_FOR_CONNECTION:
        {
            if ( LTECAT12_OK == ltecat12_check_connection( ) )
            {
                example_state = LTECAT12_CONFIGURE_FOR_EXAMPLE;
            }
            break;
        }
        case LTECAT12_CONFIGURE_FOR_EXAMPLE:
        {
            if ( LTECAT12_OK == ltecat12_cfg_for_example( ) )
            {
                example_state = LTECAT12_EXAMPLE;
            }
            break;
        }
        case LTECAT12_EXAMPLE:
        {
            ltecat12_example( );
            break;
        }
        default:
        {
            log_error( &logger, " Example state." );
            break;
        }
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

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

static err_t ltecat12_process ( void )
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = ltecat12_generic_read( &ltecat12, rx_buf, PROCESS_BUFFER_SIZE );
    if ( ( rx_size > 0 ) && ( rx_size <= APP_BUFFER_SIZE ) ) 
    {
        if ( ( app_buf_len + rx_size ) > APP_BUFFER_SIZE ) 
        {
            overflow_bytes = ( app_buf_len + rx_size ) - APP_BUFFER_SIZE;
            app_buf_len = APP_BUFFER_SIZE - rx_size;
            memmove ( app_buf, &app_buf[ overflow_bytes ], app_buf_len );
            memset ( &app_buf[ app_buf_len ], 0, overflow_bytes );
        }
        for ( rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ app_buf_len++ ] = rx_buf[ rx_cnt ];
            }
        }
        return LTECAT12_OK;
    }
    return LTECAT12_ERROR;
}

static err_t ltecat12_rsp_check ( uint8_t *rsp )
{
    uint32_t timeout_cnt = 0;
    uint32_t timeout = 120000;
    err_t error_flag = ltecat12_process( );
    if ( ( LTECAT12_OK != error_flag ) && ( LTECAT12_ERROR != error_flag ) )
    {
        return error_flag;
    }
    while ( ( 0 == strstr( app_buf, rsp ) ) &&
            ( 0 == strstr( app_buf, LTECAT12_RSP_ERROR ) ) )
    {
        error_flag = ltecat12_process( );
        if ( ( LTECAT12_OK != error_flag ) && ( LTECAT12_ERROR != error_flag ) )
        {
            return error_flag;
        }
        if ( timeout_cnt++ > timeout )
        {
            ltecat12_clear_app_buf( );
            return LTECAT12_ERROR_TIMEOUT;
        }
        Delay_ms ( 1 );
    }
    if ( strstr( app_buf, rsp ) )
    {
        return LTECAT12_OK;
    }
    else if ( strstr( app_buf, LTECAT12_RSP_ERROR ) )
    {
        return LTECAT12_ERROR_CMD;
    }
    else
    {
        return LTECAT12_ERROR_UNKNOWN;
    }
}

static void ltecat12_error_check( err_t error_flag )
{
    switch ( error_flag )
    {
        case LTECAT12_OK:
        {
            ltecat12_log_app_buf( );
            break;
        }
        case LTECAT12_ERROR:
        {
            log_error( &logger, " Overflow!" );
            break;
        }
        case LTECAT12_ERROR_TIMEOUT:
        {
            log_error( &logger, " Timeout!" );
            break;
        }
        case LTECAT12_ERROR_CMD:
        {
            log_error( &logger, " CMD!" );
            break;
        }
        case LTECAT12_ERROR_UNKNOWN:
        default:
        {
            log_error( &logger, " Unknown!" );
            break;
        }
    }
    ltecat12_clear_app_buf(  );
    Delay_ms ( 500 );
}

static void ltecat12_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" );
}

static err_t ltecat12_cfg_for_network( void )
{
    err_t func_error = LTECAT12_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) || ( DEMO_EXAMPLE == EXAMPLE_CALL ) )
    // Deregister from network
    #define DEREGISTER_FROM_NETWORK "2"
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_COPS, DEREGISTER_FROM_NETWORK );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    // Set SIM APN
    ltecat12_set_sim_apn( &ltecat12, SIM_APN );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );

    // Enable full functionality
    #define FULL_FUNCTIONALITY "1"
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_CFUN, FULL_FUNCTIONALITY );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );

    // Enable network registartion
    #define ENABLE_REG "2"
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_CREG, ENABLE_REG );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    // Automatic registration
    #define AUTOMATIC_REGISTRATION "0"
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_COPS, AUTOMATIC_REGISTRATION );
#endif
    return func_error;
}

static err_t ltecat12_check_connection( void )
{
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) || ( DEMO_EXAMPLE == EXAMPLE_CALL ) )
    #define CONNECTED "+CREG: 1"
    ltecat12_process( );
    if ( strstr( app_buf, CONNECTED ) )
    {
        Delay_ms ( 100 );
        ltecat12_process( );
        ltecat12_log_app_buf( );
        log_printf( &logger, "\r\n" );
        ltecat12_clear_app_buf( );
        // Check signal quality
        ltecat12_send_cmd( &ltecat12, LTECAT12_CMD_CESQ );
        error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
        ltecat12_error_check( error_flag );
        return error_flag;
    }
    return LTECAT12_ERROR;
#endif
    return LTECAT12_OK;
}

static err_t ltecat12_cfg_for_example ( void )
{
    err_t func_error = LTECAT12_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    #define ACTIVATE_PDP_CONTEXT "1,1"
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SICA, ACTIVATE_PDP_CONTEXT );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    #define REQ_DYNAMIC_IP "1"
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_CGPADDR, REQ_DYNAMIC_IP );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_CMGF, SMS_MODE );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
#elif ( DEMO_EXAMPLE == EXAMPLE_CALL )
    if ( LTECAT12_OK != ltecat12_max9860_cfg( &ltecat12 ) )
    {
        log_error( &logger, " MAX9860 configuration." );
        for ( ; ; );
    }
    #define ENABLE_DAI "\"GPIO/mode/DAI\",\"std\""
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SCFG, ENABLE_DAI );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    #define ENABLE_MCLK "\"GPIO/mode/MCLK\",\"std\""
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SCFG, ENABLE_MCLK );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    #define ENABLE_I2S "3,1,1,1,0,0,1,0,0"
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SAIC, ENABLE_I2S );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    #define AUDIO_MODE "6"
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SNFS, AUDIO_MODE );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
#else
    #error "No demo example selected"
#endif
    return func_error;
}

static err_t ltecat12_example ( void )
{
    err_t func_error = LTECAT12_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    uint8_t cmd_buf[ 100 ] = { 0 };
    uint8_t tcp_socket_num[ 2 ] = { '0', 0 };
    uint8_t udp_socket_num[ 2 ] = { '1', 0 };

    // Select service type Socket.
    #define SRVTYPE_SOCKET ",srvtype,\"socket\""
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, SRVTYPE_SOCKET );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISS, cmd_buf );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );

    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, SRVTYPE_SOCKET );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISS, cmd_buf );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );

    // Select connection profile.
    #define CONN_PROFILE ",conid,\"1\""
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, CONN_PROFILE );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISS, cmd_buf );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, CONN_PROFILE );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISS, cmd_buf );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    // Choose ASCII alphabet.
    #define ASCII_ALPHABET ",alphabet,1"
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, ASCII_ALPHABET );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISS, cmd_buf );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, ASCII_ALPHABET );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISS, cmd_buf );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );

    // Specify the TCP remote IP and port
    #define ADDRESS_TCP ",address,\"socktcp://"
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, ADDRESS_TCP );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, ":" );
    strcat( cmd_buf, REMOTE_PORT );
    strcat( cmd_buf, "\"" );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISS, cmd_buf );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    // Specify the UDP remote IP and port
    #define ADDRESS_UDP ",address,\"sockudp://"
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, ADDRESS_UDP );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, ":" );
    strcat( cmd_buf, REMOTE_PORT );
    strcat( cmd_buf, "\"" );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISS, cmd_buf );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    // Open TCP socket
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISO, tcp_socket_num );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    // Open UDP socket
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISO, udp_socket_num );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );

    // Get message length
    uint8_t message_len_buf[ 10 ] = { 0 };
    uint16_t message_len = strlen( MESSAGE_CONTENT );
    uint16_to_str( message_len, message_len_buf );
    l_trim( message_len_buf );
    r_trim( message_len_buf );

    // Write message to TCP socket and read response
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISW, cmd_buf );
    Delay_ms ( 100 );
    ltecat12_generic_write ( &ltecat12, MESSAGE_CONTENT, message_len );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    Delay_ms ( 1000 );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISR, cmd_buf );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );

    // Write message to UDP socket and read response
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISW, cmd_buf );
    Delay_ms ( 100 );
    ltecat12_generic_write ( &ltecat12, MESSAGE_CONTENT, message_len );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    Delay_ms ( 1000 );
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISR, cmd_buf );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    // Close TCP socket
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISC, tcp_socket_num );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    // Close UDP socket
    ltecat12_send_cmd_with_params( &ltecat12, LTECAT12_CMD_SISC, udp_socket_num );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    // Check SMS mode
    #define CMGF_PDU "+CMGF: 0"
    #define CMGF_TXT "+CMGF: 1"
    ltecat12_send_cmd_check( &ltecat12, LTECAT12_CMD_CMGF );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    if ( strstr( app_buf, CMGF_PDU ) )
    {
        ltecat12_error_check( error_flag );
        // Send SMS in PDU mode
        ltecat12_send_sms_pdu( &ltecat12, SIM_SMSC, PHONE_NUMBER, MESSAGE_CONTENT );
        error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
        func_error |= error_flag;
    }
    else if ( strstr( app_buf, CMGF_TXT ) )
    {
        ltecat12_error_check( error_flag );
        // Send SMS in TXT mode
        ltecat12_send_sms_text ( &ltecat12, PHONE_NUMBER, MESSAGE_CONTENT );
        error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
        func_error |= error_flag;
    }
    ltecat12_error_check( error_flag );
    // 30 seconds delay
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
#elif ( DEMO_EXAMPLE == EXAMPLE_CALL )
    uint8_t cmd_buf[ 100 ] = { 0 };
    
    strcpy( cmd_buf, LTECAT12_CMD_ATD );
    ltecat12_clear_app_buf( );
    strcat( cmd_buf, PHONE_NUMBER );
    strcat( cmd_buf, ";" );
    
    log_printf( &logger, " Calling selected number \r\n" );
    ltecat12_send_cmd( &ltecat12, cmd_buf );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    ltecat12_clear_app_buf( );
    log_printf( &logger, "Dialing \r\n" );
    #define CHECK_DIALING "+CLCC: 1, 0, 2, "      
    error_flag = ltecat12_rsp_check( CHECK_DIALING );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    log_printf( &logger, "Ringing \r\n" );
    #define CHECK_RINGING "+CLCC: 1, 0, 3, "      
    error_flag = ltecat12_rsp_check( CHECK_RINGING );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    
    // 10 seconds delay
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    
    log_printf( &logger, "Hanging up \r\n" );
    ltecat12_send_cmd( &ltecat12, LTECAT12_CMD_CHUP );
    ltecat12_clear_app_buf( );
    error_flag = ltecat12_rsp_check( LTECAT12_RSP_OK );
    func_error |= error_flag;
    ltecat12_error_check( error_flag );
    ltecat12_clear_app_buf( );
    
    // 20 seconds delay
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
#else
    #error "No demo example selected"
#endif
    return func_error;
}

// ------------------------------------------------------------------------ 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.