Beginner
10 min

Your all-in-one solution for location and connectivity based on SIM808 and MK64FN1M0VDC12

GPS and GSM/GPRS unite: Your ultimate tracking solution

GSM-GPS Click with Clicker 2 for Kinetis

Published Sep 09, 2023

Click board™

GSM-GPS Click

Dev. board

Clicker 2 for Kinetis

Compiler

NECTO Studio

MCU

MK64FN1M0VDC12

With a focus on simplifying connectivity and location tracking, we aim to empower various businesses with a single, integrated device that provides real-time GPS data alongside reliable GSM/GPRS communication capabilities

A

A

Hardware Overview

How does it work?

GSM-GPS Click is based on the SIM808, a GSM/GPRS+GPS module from SIMCom. The SIM808 is a highly integrated module and supports 0710 MUX protocol, TCP/UDP protocol, FTP/HTTP, MMS, POP3/SMTP, DTMF, jamming detection, audio record, SSL, optional Bluetooth 3.0, TTS CN, and has embedded AT. For connection with the outside world, this Click board™ features two SMA connectors for both GSM/GPRS and GPS radios, for which appropriate antennas MIKROE has in its offer for improved range and received signal strength. In addition, there is a micro-SIM slot beneath the GSM-GPS Click board and a micro-USB connector for interfacing it with a PC. The SIM808 has three operational modes. The Normal mode has several functions: GSM/GPRS Sleep, GSM Idle, GSM Talk, GPRS Standby, GPRS Data, and Charge. The SIM808 module uses these functions to transfer the data, connect between two subscribers, register to the GSM network, and more. The Power Down mode shuts down the baseband part of the module, the software is not active, and the serial port is not accessible, while the RTC remains active. In Minimum Functionality mode, the RF part of the module will not work,

the SIM card will not be accessible, or both, but the serial port will still be accessible. The AT commands set the last two operational modes. The GPRS class 12 of the SIM808 can achieve up to 85.6Kbps data rates (downlink/uplink) while using a CS-4 coding scheme. It can handle SMS via GSM/GPRS by point-to-point MO and MT, SMS cell broadcast, text, and PDU mode. There is also support for PBCCH, PP-stack, and USSD. The GPS receiver has 22 tracking and 66 acquisition channels, with a tracking sensitivity of -165dBm. The Cold Start is less sensitive with a -148dBm. The important part is TTFF, which in Hot Start is less than a second but comes in some 32s for Cold Start. The accuracy is under 2.5m CEP in a horizontal position. There are several LEDs for visual status presentation. The PPS stands for Pulse Per Second and is related to the receiver time. The TXD LED presents the network status, and the STA LED presents the power-on status. The GSM-GPS features a 4-pin header, the interface for differential audio output, and input for connecting the speaker and the microphone. The SIM808 uses the UART interface with commonly used UART RX and TX pins as its default

communication protocol for communication with the host MCU, supporting baud rates from 1200bps up to 11520bps. The UART interface also comes with the RTS (request to send) and CTS (clear to send) pins. In addition, the Click board™ features other functions accessible through mikroBUS™ signals, such as Power-on status on the STA pin (the same status as on the STA LED). The power-down of the SIM808 can be achieved by pulling LOW for 1 second the PWK pin (power key). There is a ring indicator (RI) for apparent purposes. For logic level translation, this Click board™ uses the TXB0106, a 6-bit bidirectional level-shifting and voltage translator with auto-direction sensing and ESD protection from Texas Instruments. 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. However, the 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.

GSM-GPS Click hardware overview image

Features overview

Development board

Clicker 2 for Kinetis is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit ARM Cortex-M4F microcontroller, the MK64FN1M0VDC12 from NXP Semiconductors, two mikroBUS™ sockets for Click board™ connectivity, a USB connector, LED indicators, buttons, a JTAG programmer connector, and two 26-pin headers for interfacing with external electronics. Its compact design with clear and easily recognizable silkscreen markings allows you to build gadgets with unique functionalities and

features quickly. Each part of the Clicker 2 for Kinetis development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the Clicker 2 for Kinetis programming method, using a USB HID mikroBootloader or an external mikroProg connector for Kinetis programmer, the Clicker 2 board also includes a clean and regulated power supply module for the development kit. It provides two ways of board-powering; through the USB Micro-B cable, where onboard voltage regulators provide the appropriate voltage levels to each component on the board, or

using a Li-Polymer battery via an onboard battery connector. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several user-configurable buttons and LED indicators. Clicker 2 for Kinetis is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

Clicker 2 for Kinetis dimensions image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

1024

Silicon Vendor

NXP

Pin count

121

RAM (Bytes)

262144

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.

GSM-GPS Click accessories image

Used MCU Pins

mikroBUS™ mapper

Module Status
PB2
AN
Module Power-Up
PB11
RST
UART RTS
PC4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
UART RI
PA10
PWM
UART CTS
PB13
INT
UART TX
PD3
TX
UART RX
PD2
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

GSM-GPS Click Schematic schematic

Step by step

Project assembly

Clicker 2 for PIC32MZ front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Clicker 2 for Kinetis as your development board.

Clicker 2 for PIC32MZ front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Micro B Connector Clicker 2 Access - 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
Flip&Click PIC32MZ 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 GSM-GPS Click driver.

Key functions:

  • gsmgps_send_cmd_with_parameter - Send command function with parameter

  • gsmgps_send_sms_pdu - GSM-GPS send SMS in PDU mode

  • gsmgps_generic_parser - Generic parser function.

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 Gsmgps Click example
 * 
 * # Description
 * This example reads and processes data from GSM-GPS click.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver and powers up the module, then sets default configuration 
 * for connecting the device to network.
 * 
 * ## Application Task  
 * Waits for the device to connect to network, then waits for the GPS position fix. Once it get a fix, 
 * it sends an SMS with GPS info to the selected phone number approximately every 40 seconds.
 * 
 * ## Additional Function
 * - static void gsmgps_clear_app_buf ( void )
 * - static void gsmgps_error_check( err_t error_flag )
 * - static void gsmgps_log_app_buf ( void )
 * - static void gsmgps_check_connection( void )
 * - static err_t gsmgps_rsp_check ( void )
 * - static err_t gsmgps_process ( void )
 * - static void gps_parser_application ( void )
 * 
 * @note 
 * In order for the example to work, user needs to set the phone number to which he wants 
 * to send an SMS, and also will need to set an APN and SMSC (required for PDU mode only) of entered SIM card.
 * Enter valid data for the following macros: SIM_APN, SIM_SMSC and PHONE_NUMBER_TO_MESSAGE.
 * E.g. 
    SIM_APN "vipmobile"
    SIM_SMSC "+381610401"
    PHONE_NUMBER_TO_MESSAGE "+381659999999"
 * 
 * @author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "gsmgps.h"
#include "string.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 SIM_SMSC                            ""  // Set valid SMS Service Center Address - only in PDU mode
#define PHONE_NUMBER_TO_MESSAGE             "" // Set Phone number to message

#define PROCESS_BUFFER_SIZE                 256

#define WAIT_FOR_CONNECTION                 0
#define CONNECTED_TO_NETWORK                1

static gsmgps_t gsmgps;
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;
static uint8_t gps_parser_flag = 0;
static uint8_t gps_info_message[ 200 ] = { 0 };

/**
 * @brief GSM-GPS clearing application buffer.
 * @details This function clears memory of application buffer and reset its length and counter.
 * @note None.
 */
static void gsmgps_clear_app_buf ( void );

/**
 * @brief GSM-GPS 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 gsmgps_process ( void );

/**
 * @brief GSM-GPS check for errors.
 * @details This function checks for different types of errors and logs them on UART.
 * @note None.
 */
static void gsmgps_error_check( err_t error_flag );

/**
 * @brief GSM-GPS logs application buffer.
 * @details This function logs data from application buffer.
 * @note None.
 */
static void gsmgps_log_app_buf ( void );

/**
 * @brief GSM-GPS 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 gsmgps_rsp_check ( void );

/**
 * @brief GSM-GPS check connection.
 * @details This function checks connection to the network and 
 *          logs that status to UART.
 * 
 * @note None.
 */
static void gsmgps_check_connection( void );

/**
 * @brief GPS parser application.
 * @param rsp Response buffer.
 * @details This function logs GPS data on the USB UART and stores data in gps_info_message buffer.
 * 
 * @note None.
 */
static void gps_parser_application ( char *rsp );

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    gsmgps_cfg_t cfg;

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

    gsmgps_cfg_setup( &cfg );
    GSMGPS_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    gsmgps_init( &gsmgps, &cfg );

    gsmgps_module_power( &gsmgps, GSMGPS_MODULE_POWER_ON );
    
    // dummy read
    gsmgps_process( );
    gsmgps_clear_app_buf( );
    // AT
    gsmgps_send_cmd( &gsmgps, GSMGPS_CMD_AT );
    app_error_flag = gsmgps_rsp_check( );
    gsmgps_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // ATI - product information
    gsmgps_send_cmd( &gsmgps, GSMGPS_CMD_ATI );
    app_error_flag = gsmgps_rsp_check(  );
    gsmgps_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // CGMR - firmware version
    gsmgps_send_cmd( &gsmgps, GSMGPS_CMD_CGMR );
    app_error_flag = gsmgps_rsp_check(  );
    gsmgps_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // COPS - deregister from network
    gsmgps_send_cmd_with_parameter( &gsmgps, GSMGPS_CMD_COPS, "2" );
    app_error_flag = gsmgps_rsp_check(  );
    gsmgps_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // CGDCONT - set sim apn
    gsmgps_set_sim_apn( &gsmgps, SIM_APN );
    app_error_flag = gsmgps_rsp_check(  );
    gsmgps_error_check( app_error_flag );
    Delay_ms( 500 );
     
    // CFUN - full funtionality
    gsmgps_send_cmd_with_parameter( &gsmgps, GSMGPS_CMD_CFUN, "1" );
    app_error_flag = gsmgps_rsp_check(  );
    gsmgps_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // COPS - automatic mode
    gsmgps_send_cmd_with_parameter( &gsmgps, GSMGPS_CMD_COPS, "0" );
    app_error_flag = gsmgps_rsp_check(  );
    gsmgps_error_check( app_error_flag );
    Delay_ms( 2000 );
    
    // CREG - network registration status
    gsmgps_send_cmd_with_parameter( &gsmgps, GSMGPS_CMD_CREG, "2" );
    app_error_flag = gsmgps_rsp_check(  );
    gsmgps_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // CIMI - request IMSI
    gsmgps_send_cmd( &gsmgps, GSMGPS_CMD_CIMI );
    app_error_flag = gsmgps_rsp_check(  );
    gsmgps_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // CGNSPWR - power ON GPS
    gsmgps_send_cmd_with_parameter( &gsmgps, GSMGPS_CMD_CGNSPWR, "1" );
    app_error_flag = gsmgps_rsp_check(  );
    gsmgps_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 )
    {
        // CGATT - request IMSI
        gsmgps_send_cmd_check( &gsmgps, GSMGPS_CMD_CGATT );
        app_error_flag = gsmgps_rsp_check(  );
        gsmgps_error_check( app_error_flag );
        Delay_ms( 500 );
        
        // CREG - network registration status
        gsmgps_send_cmd_check( &gsmgps, GSMGPS_CMD_CREG );
        app_error_flag = gsmgps_rsp_check(  );
        gsmgps_error_check( app_error_flag );
        Delay_ms( 500 );
        
        // CSQ - signal quality
        gsmgps_send_cmd( &gsmgps, GSMGPS_CMD_CSQ );
        app_error_flag = gsmgps_rsp_check(  );
        gsmgps_error_check( app_error_flag );
        Delay_ms( 5000 );
    }
    else
    {
        log_info( &logger, "CONNECTED TO NETWORK" );
        
        // SMS message format - PDU mode
        gsmgps_send_cmd_with_parameter( &gsmgps, GSMGPS_CMD_CMGF, "0" );
        app_error_flag = gsmgps_rsp_check(  );
        gsmgps_error_check( app_error_flag );
        Delay_ms( 3000 );
        
        for( ; ; )
        {   
            // Get GPS info
            gps_parser_flag = 1;
            gsmgps_send_cmd_with_parameter( &gsmgps, GSMGPS_CMD_CGPSINF, "2" );
            app_error_flag = gsmgps_rsp_check(  );
            gsmgps_error_check( app_error_flag );
            Delay_ms( 3000 );
            
            if ( gps_parser_flag == 0 )
            {
                log_printf( &logger, "> Sending message to phone number...\r\n" );
                gsmgps_send_sms_pdu ( &gsmgps, SIM_SMSC, PHONE_NUMBER_TO_MESSAGE, gps_info_message );
                app_error_flag = gsmgps_rsp_check(  );
                gsmgps_error_check( app_error_flag );
                Delay_ms( 10000 );
                Delay_ms( 10000 );
                Delay_ms( 10000 );
            }
        }
    }
}

void main ( void )
{
    application_init( );

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

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

static err_t gsmgps_process ( void )
{
    err_t return_flag = APP_ERROR_DRIVER;
    int32_t rx_size;
    char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
    
    rx_size = gsmgps_generic_read( &gsmgps, 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 )
        {
            gsmgps_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--;
                buf_cnt--;
            }
        }
    } 

    return return_flag;
}

static err_t gsmgps_rsp_check ( void )
{
    uint16_t timeout_cnt = 0;
    uint16_t timeout = 10000;
    
    err_t error_flag = gsmgps_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 = gsmgps_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 ) )
            {
                gsmgps_send_cmd( &gsmgps, GSMGPS_CMD_AT );
                gsmgps_process(  );
                Delay_ms( 100 );
            }
            gsmgps_clear_app_buf(  );
            return APP_ERROR_TIMEOUT;
        }
        
        Delay_ms( 1 );
    }
    
    gsmgps_check_connection();
    
    gsmgps_log_app_buf();
    
    return APP_OK;
}

static void gsmgps_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 gsmgps_log_app_buf ( void )
{
    if ( gps_parser_flag == 1 )
    {
        gps_parser_application( app_buf );
        
    }
    else
    {
        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-----------------------------------\r\n" );
    }
    
    gsmgps_clear_app_buf(  );
}

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

static void gps_parser_application ( char *rsp )
{
    char element_buf[ 200 ] = { 0 };
    memset( gps_info_message, 0, 200 ); 
    gsmgps_generic_parser( rsp, GSMGPS_NEMA_GPGGA, GSMGPS_GPGGA_LATITUDE, element_buf );
    if ( strcmp( element_buf, "0000.0000" ) != 0 )
    {
        strcpy( gps_info_message, "GSM-GPS click - GPS info\n" );
        strcat( gps_info_message, "Latitude: " );
        strcat( gps_info_message, element_buf );
        log_printf( &logger, "Latitude:  %s\r\n", element_buf );
        gsmgps_generic_parser( rsp, GSMGPS_NEMA_GPGGA, GSMGPS_GPGGA_LONGITUDE, element_buf );
        strcat( gps_info_message, "\nLongitude: " );
        strcat( gps_info_message, element_buf );
        log_printf( &logger, "Longitude:  %s\r\n", element_buf );
        memset( element_buf, 0, sizeof( element_buf ) );
        gsmgps_generic_parser( rsp, GSMGPS_NEMA_GPGGA, GSMGPS_GPGGA_ALTITUDE, element_buf );
        strcat( gps_info_message, "\nAltitude: " );
        strcat( gps_info_message, element_buf );
        log_printf( &logger, "Altitude: %s m\r\n", element_buf );  
        gps_parser_flag = 0;
    }
    else
    {
        log_printf( &logger, "Waiting for the position fix..." );
    }
    log_printf( &logger, "\r\n-----------------------------------\r\n" );
}

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