Intermediate
20 min

Unleash the power of UTMS for North American businesses with UG95 and PIC18F46K40

Connecting communities, one frequency band at a time!

3G-AA Click (for United States) with Curiosity HPC

Published Nov 01, 2023

Click board™

3G-AA Click (for United States)

Dev Board

Curiosity HPC

Compiler

NECTO Studio

MCU

PIC18F46K40

Our cutting-edge cellular network solution guarantees uninterrupted communication across all UTMS frequency bands in North America, ensuring you stay connected when it matters most

A

A

Hardware Overview

How does it work?

3G-AA Click is based on the UG95-A, an ultra-small UMTS/HSPA module with high-speed wireless connectivity from Quectel. This module is the main component of the Click board™, consisting of several internal blocks or sections, such as an antenna switching section, RF transceiver section, memory, power management, and most importantly - the cellular baseband processor. This section contains the logic necessary for managing the other sections and provides the interface to the host MCU. The Micro SIM card holder on the back of the Click board™ is used to install a microSIM card. This device cannot be used without a valid SIM card, which allows connection to the cellular network. Both 1.8V and 3V SIM card types are supported. The Quectel UG95 offers the PCM interface used for digital audio. The MAX9860, a 16-bit mono audio voice CODEC IC from Analog Devices, provides the 3G-AA Click with voice communication. The MAX9860 IC uses

the PCM and I2C interfaces to communicate with the Quectel UG95 module. This IC provides a clean and audible analog interface for connecting the headset, with one audio output channel and one microphone input channel. The headset can be connected via the onboard 3.5mm audio jack. 3G-AA Click is also equipped with a micro-USB connector. It allows the module to be powered and configured by a personal computer (PC). Quectel offers a software suite that can be used with the 3G-AA Click board™. 3G-AA Click uses a standard 2-wire UART interface to communicate with the host MCU with commonly used UART RX and TX. UART interface supports baud rates of 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, and 921600bps, with the default setting to automatic baud rate detection, between 4800 and 115200. The UART interface can be used for data transmission, AT communication, or firmware upgrades. The 3G-AA Click offers full

hardware flow control over the UART RTS and CTS pins. As the UG95 is internally supplied by 1.8V, the 3G-AA Click uses the TXB0106, a 6-bit bidirectional level shifting and voltage translator from Texas Instruments. In addition, the 3G-AA Click has a ringing RI indicator and the PWK as a power key, which is used during the power-up sequence. The STA is a status pin used to signal the status of the device, in addition to the STAT LED. The other LED is TXD, which indicates the network status. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the I/O 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.

3G-AA Click (for United States) hardware overview image

Features overview

Development board

Curiosity HPC, standing for Curiosity High Pin Count (HPC) development board, supports 28- and 40-pin 8-bit PIC MCUs specially designed by Microchip for the needs of rapid development of embedded applications. This board has two unique PDIP sockets, surrounded by dual-row expansion headers, allowing connectivity to all pins on the populated PIC MCUs. It also contains a powerful onboard PICkit™ (PKOB), eliminating the need for an external programming/debugging tool, two mikroBUS™ sockets for Click board™ connectivity, a USB connector, a set of indicator LEDs, push button switches and a variable potentiometer. All

these features allow you to combine the strength of Microchip and Mikroe and create custom electronic solutions more efficiently than ever. Each part of the Curiosity HPC development board contains the components necessary for the most efficient operation of the same board. An integrated onboard PICkit™ (PKOB) allows low-voltage programming and in-circuit debugging for all supported devices. When used with the MPLAB® X Integrated Development Environment (IDE, version 3.0 or higher) or MPLAB® Xpress IDE, in-circuit debugging allows users to run, modify, and troubleshoot their custom software and hardware

quickly without the need for additional debugging tools. Besides, it includes a clean and regulated power supply block for the development board via the USB Micro-B connector, alongside all communication methods that mikroBUS™ itself supports. Curiosity HPC development board allows you to create a new application in just a few steps. Natively supported by Microchip software tools, it covers many aspects of prototyping thanks to many number of different Click boards™ (over a thousand boards), the number of which is growing daily.

Curiosity HPC double image

Microcontroller Overview

MCU Card / MCU

PIC18F46K40

Architecture

PIC

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

3728

You complete me!

Accessories

Rubber Antenna GSM/GPRS Right Angle is the perfect companion for all GSM Click boards™ in our extensive lineup. This specialized antenna is designed to optimize your wireless connectivity with impressive features. With a wide frequency range spanning 824-894/1710-1990MHz or 890-960/1710-1890MHz, it can handle various frequency bands, ensuring a seamless and reliable connection. The antenna boasts an impedance of 50 Ohms and a gain of 2dB, enhancing signal reception and transmission. Its 70/180MHz bandwidth provides flexibility for diverse applications. The vertical polarization further enhances its performance. With a maximum input power capacity of 50W, this antenna ensures robust communication even under demanding conditions. Measuring a compact 50mm in length and featuring an SMA male connector, the Rubber Antenna GSM/GPRS Right Angle is a versatile and compact solution for your wireless communication needs.

3G-AA Click accessories image

Used MCU Pins

mikroBUS™ mapper

Module Status
RA1
AN
Power-Up module
RD0
RST
UART RTS
RA3
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
UART RI
RC2
PWM
UART CTS
RB5
INT
UART TX
RC6
TX
UART RX
RC7
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

3G-AA Click (for United States) Schematic schematic

Step by step

Project assembly

Curiosity HPC front no-mcu image hardware assembly

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

Curiosity HPC front no-mcu image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Curiosity HPC 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
Necto DIP image step 7 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

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for 3G-AA Click driver.

Key functions:

  • c3gea_set_sim_apn - This function sets APN for sim card

  • c3gea_send_sms_text - This function sends text message to a phone number

  • c3gea_send_sms_pdu - This function sends text message to a phone number in PDU mode.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief 3G-AA Click Example.
 *
 * # Description
 * Application example shows device capability of connecting to the network and
 * sending SMS or TCP/UDP messages using standard "AT" commands.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver, tests the communication by sending "AT" command, and after that restarts the device.
 *
 * ## Application Task
 * Application task is split in few stages:
 *  - C3GAA_CONFIGURE_FOR_NETWORK:
 * Sets configuration to device to be able to connect to the network.
 *
 *  - C3GAA_WAIT_FOR_CONNECTION:
 * Waits for the network registration indicated via CREG URC event and then checks
 * the connection status.
 *
 *  - C3GAA_CONFIGURE_FOR_EXAMPLE:
 * Sets the device configuration for sending SMS or TCP/UDP messages depending on the selected demo example.
 *
 *  - C3GAA_EXAMPLE:
 * Depending on the selected demo example, it sends an SMS message (in PDU or TXT mode) or TCP/UDP message.
 *
 * By default, the TCP/UDP example is selected.
 *
 * ## Additional Function
 * - static void c3gaa_clear_app_buf ( void )
 * - static err_t c3gaa_process ( void )
 * - static void c3gaa_error_check( err_t error_flag )
 * - static void c3gaa_log_app_buf ( void )
 * - static err_t c3gaa_rsp_check ( uint8_t *rsp )
 * - static err_t c3gaa_configure_for_connection( void )
 * - static err_t c3gaa_check_connection( void )
 * - static err_t c3gaa_configure_for_messages( void )
 * - static err_t c3gaa_send_message( 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 Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "c3gaa.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 DEMO_EXAMPLE                        EXAMPLE_TCP_UDP // Example selection macro

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

// SMS example parameters
#define SIM_SMSC                            ""              // Set valid SMS Service Center Address - only in SMS PDU mode
#define PHONE_NUMBER_TO_MESSAGE             ""              // Set Phone number to message
#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                     "3G-AA 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
{
    C3GAA_CONFIGURE_FOR_NETWORK = 1,
    C3GAA_WAIT_FOR_CONNECTION,
    C3GAA_CONFIGURE_FOR_EXAMPLE,
    C3GAA_EXAMPLE

} c3gaa_example_state_t;

static c3gaa_t c3gaa;
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 c3gaa_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 c3gaa_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 c3gaa_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 c3gaa_error_check ( err_t error_flag );

/**
 * @brief Logs application buffer.
 * @details This function logs data from application buffer.
 */
static void c3gaa_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 c3gaa_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 c3gaa_configure_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 c3gaa_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 c3gaa_configure_for_example ( void );

/**
 * @brief Execute example.
 * @details This function executes SMS or TCP/UDP 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 c3gaa_example ( void );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    c3gaa_cfg_t c3gaa_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.
    c3gaa_cfg_setup( &c3gaa_cfg );
    C3GAA_MAP_MIKROBUS( c3gaa_cfg, MIKROBUS_1 );
    if ( UART_ERROR == c3gaa_init( &c3gaa, &c3gaa_cfg ) )
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );
        for ( ; ; );
    }
    
    c3gaa_process( );
    c3gaa_clear_app_buf( );

    // Check communication
    c3gaa_send_cmd( &c3gaa, C3GAA_CMD_AT );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    c3gaa_error_check( error_flag );
    
    // Restart device
    #define RESTART_DEVICE "1,1"
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_CFUN, RESTART_DEVICE );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    c3gaa_error_check( error_flag );
    
    log_info( &logger, " Application Task " );
    example_state = C3GAA_CONFIGURE_FOR_NETWORK;
}

void application_task ( void )
{
    switch ( example_state )
    {
        case C3GAA_CONFIGURE_FOR_NETWORK:
        {
            if ( C3GAA_OK == c3gaa_configure_for_network( ) )
            {
                example_state = C3GAA_WAIT_FOR_CONNECTION;
            }
            break;
        }
        case C3GAA_WAIT_FOR_CONNECTION:
        {
            if ( C3GAA_OK == c3gaa_check_connection( ) )
            {
                example_state = C3GAA_CONFIGURE_FOR_EXAMPLE;
            }
            break;
        }
        case C3GAA_CONFIGURE_FOR_EXAMPLE:
        {
            if ( C3GAA_OK == c3gaa_configure_for_example( ) )
            {
                example_state = C3GAA_EXAMPLE;
            }
            break;
        }
        case C3GAA_EXAMPLE:
        {
            c3gaa_example( );
            break;
        }
        default:
        {
            log_error( &logger, " Example state." );
            break;
        }
    }
}

int main ( void ) 
{
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

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

static err_t c3gaa_process ( void )
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    rx_size = c3gaa_generic_read( &c3gaa, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = app_buf_len;
        if ( ( ( app_buf_len + rx_size ) > APP_BUFFER_SIZE ) && ( app_buf_len > 0 ) ) 
        {
            buf_cnt = APP_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - APP_BUFFER_SIZE );
            memmove ( app_buf, &app_buf[ APP_BUFFER_SIZE - buf_cnt ], buf_cnt );
        }
        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
                if ( app_buf_len < APP_BUFFER_SIZE )
                {
                    app_buf_len++;
                }
            }
        }
        return C3GAA_OK;
    }
    return C3GAA_ERROR;
}

static err_t c3gaa_rsp_check ( uint8_t *rsp )
{
    uint32_t timeout_cnt = 0;
    uint32_t timeout = 120000;
    c3gaa_clear_app_buf( );
    c3gaa_process( );
    while ( ( 0 == strstr( app_buf, rsp ) ) &&
            ( 0 == strstr( app_buf, C3GAA_RSP_ERROR ) ) )
    {
        c3gaa_process( );
        if ( timeout_cnt++ > timeout )
        {
            c3gaa_clear_app_buf( );
            return C3GAA_ERROR_TIMEOUT;
        }
        Delay_ms( 1 );
    }
    Delay_ms( 100 );
    c3gaa_process( );
    if ( strstr( app_buf, rsp ) )
    {
        return C3GAA_OK;
    }
    else if ( strstr( app_buf, C3GAA_RSP_ERROR ) )
    {
        return C3GAA_ERROR_CMD;
    }
    else
    {
        return C3GAA_ERROR_UNKNOWN;
    }
}

static void c3gaa_error_check ( err_t error_flag )
{
    switch ( error_flag )
    {
        case C3GAA_OK:
        {
            c3gaa_log_app_buf( );
            break;
        }
        case C3GAA_ERROR:
        {
            log_error( &logger, " Overflow!" );
            break;
        }
        case C3GAA_ERROR_TIMEOUT:
        {
            log_error( &logger, " Timeout!" );
            break;
        }
        case C3GAA_ERROR_CMD:
        {
            log_error( &logger, " CMD!" );
            break;
        }
        case C3GAA_ERROR_UNKNOWN:
        default:
        {
            log_error( &logger, " Unknown!" );
            break;
        }
    }
    Delay_ms( 500 );
}

static void c3gaa_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 ] );
    }
}

static err_t c3gaa_configure_for_network ( void )
{
    err_t func_error = C3GAA_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    Delay_ms ( 5000 );
    // Deregister from network
    #define DEREGISTER_FROM_NETWORK "2"
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_COPS, DEREGISTER_FROM_NETWORK );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
    
    // Set SIM APN
    c3gaa_set_sim_apn( &c3gaa, SIM_APN );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );

    // Enable full functionality
    #define FULL_FUNCTIONALITY "1"
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_CFUN, FULL_FUNCTIONALITY );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );

    // Enable network registartion
    #define ENABLE_REG "2"
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_CREG, ENABLE_REG );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
    
    // Automatic registration
    #define AUTOMATIC_REGISTRATION "0"
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_COPS, AUTOMATIC_REGISTRATION );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
#endif
    return func_error;
}

static err_t c3gaa_check_connection ( void )
{
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    #define CONNECTED "+CREG: 2,1"
    c3gaa_send_cmd_check ( &c3gaa, C3GAA_CMD_CREG );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    c3gaa_error_check( error_flag );
    if ( strstr( app_buf, CONNECTED ) )
    {
        Delay_ms( 100 );
        c3gaa_process( );
        c3gaa_log_app_buf( );
        log_printf( &logger, "\r\n" );
        c3gaa_clear_app_buf( );
        // Check signal quality
        c3gaa_send_cmd( &c3gaa, C3GAA_CMD_CSQ );
        error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
        c3gaa_error_check( error_flag );
        return error_flag;
    }
    Delay_ms ( 1000 );
    return C3GAA_ERROR;
#endif
    return C3GAA_OK;
}

static err_t c3gaa_configure_for_example ( void )
{
    err_t func_error = C3GAA_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    #define ACTIVATE_PDP_CONTEXT "1"
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_QIACT, ACTIVATE_PDP_CONTEXT );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_CMGF, SMS_MODE );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
#else
    #error "No demo example selected"
#endif
    return func_error;
}

static err_t c3gaa_example ( void )
{
    err_t func_error = C3GAA_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 };
    #define CONTEXT_ID "1,"

    // Open TCP socket.
    #define TCP_SERVICE_TYPE ",\"TCP\","
    strcpy( cmd_buf, CONTEXT_ID );
    strcat( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, TCP_SERVICE_TYPE );
    strcat( cmd_buf, "\"" );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, "\"" );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, REMOTE_PORT );
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_QIOPEN, cmd_buf );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
    
    // Open UDP socket.
    #define UDP_SERVICE_TYPE ",\"UDP\","
    strcpy( cmd_buf, CONTEXT_ID );
    strcat( cmd_buf, udp_socket_num );
    strcat( cmd_buf, UDP_SERVICE_TYPE );
    strcat( cmd_buf, "\"" );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, "\"" );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, REMOTE_PORT );
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_QIOPEN, cmd_buf );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_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 );
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_QISEND, cmd_buf );
    Delay_ms ( 100 );
    c3gaa_generic_write ( &c3gaa, MESSAGE_CONTENT, message_len );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
    Delay_ms ( 1000 );
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_QIRD, cmd_buf );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_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 );
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_QISEND, cmd_buf );
    Delay_ms ( 100 );
    c3gaa_generic_write ( &c3gaa, MESSAGE_CONTENT, message_len );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
    Delay_ms ( 1000 );
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_QIRD, cmd_buf );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
    
    // Close TCP socket
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_QICLOSE, tcp_socket_num );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
    
    // Close UDP socket
    c3gaa_send_cmd_with_par( &c3gaa, C3GAA_CMD_QICLOSE, udp_socket_num );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
    Delay_ms( 5000 );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    // Check SMS mode
    #define CMGF_PDU "+CMGF: 0"
    #define CMGF_TXT "+CMGF: 1"
    c3gaa_send_cmd_check( &c3gaa, C3GAA_CMD_CMGF );
    error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
    func_error |= error_flag;
    c3gaa_error_check( error_flag );
    if ( strstr( app_buf, CMGF_PDU ) )
    {
        // Send SMS in PDU mode
        c3gaa_send_sms_pdu( &c3gaa, SIM_SMSC, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
        error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
        func_error |= error_flag;
        c3gaa_error_check( error_flag );
    }
    else if ( strstr( app_buf, CMGF_TXT ) )
    {
        // Send SMS in TXT mode
        c3gaa_send_sms_text ( &c3gaa, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
        error_flag = c3gaa_rsp_check( C3GAA_RSP_OK );
        func_error |= error_flag;
        c3gaa_error_check( error_flag );
    }
    Delay_ms( 10000 );
    Delay_ms( 10000 );
    Delay_ms( 10000 );
#else
    #error "No demo example selected"
#endif
    return func_error;
}

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

Additional Support

Resources