Intermediate
30 min

Make your GPS tracking device with M20050-1 and ATmega644P

Your beacon of navigation!

GPS 5 Click with EasyAVR v7

Published Apr 04, 2023

Click board™

GPS 5 Click

Dev. board

EasyAVR v7

Compiler

NECTO Studio

MCU

ATmega644P

Stay connected to the world around you and find your way with ease

A

A

Hardware Overview

How does it work?

GPS 5 Click is based on the M20050-1, an integrated GNSS receiver module with an integrated antenna incorporating the MediaTek MT3333 flash chip from Antenova. The M20050-1 tracks 3 GNSS constellations concurrently (GPS+Galileo+GLONASS or GPS+Beidou) to considerably enhance the location and has configurable low power modes alongside acquisition and tracking sensitivity of -163dBm and -165dBm. This module offers indoor and outdoor multi-path detection and compensation and has an accurate 0.5ppm TXCO that ensures short TTFF besides an active interference cancellation (AIC) feature. This Click board is ideal for asset tracking/ personal safety, navigation devices, and sports equipment applications based on good attributes. The M20050-1 has three power-saving modes: Standby, Backup, and Periodic. Standby mode is a power-saving mode initiated with a hardware signal routed on the STB pin of the mikroBUS™ socket or by a software command.

It shuts down the RF section of the module, putting the processor into Standby mode. The RTC is kept alive, and the RAM power is maintained to keep the module configuration. Periodic mode is a user-configurable mode that reduces current consumption by only waking the module for short periods to maintain FIX data. Backup mode is accessed due to the absence of the main board power supply VCC. For this reason, there is an additional backup power supply in the form of a battery that powers the RAM and RTC sections of the receiver and needs to be applied at all times for Backup mode to run correctly. Once initiated, the RTC and all configurations are saved along with any ephemeris data to allow quick TTFF once the VCC is re-applied. GPS 5 Click communicates with MCU using the UART interface with commonly used UART RX and TX pins operating at 115200bps by default to transmit and exchange data with the host MCU. It also possesses an active-low reset signal routed on the

RST pin of the mikroBUS™ socket that activates a hardware reset of the M20050-1. The reset function can also be used using an onboard RESET button. In addition to precise positioning, the GPS 5 Click also has an accurate timing signal indicated via a red LED indicator marked as 1PPS, a blue LED indicator marked with FIX, which shows once a GPS fix has been obtained, as well as the possibility of using an external active antenna which can also be found in our offer, activated through EN pin of the mikroBUS™ socket. This Click board™ can only be operated with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. However, the Click board™ comes equipped with a library containing functions and an example code that can be used as a reference for further development.

GPS 5 Click top side image
GPS 5 Click lateral side image
GPS 5 Click bottom side image

Features overview

Development board

EasyAVR v7 is the seventh generation of AVR development boards specially designed for the needs of rapid development of embedded applications. It supports a wide range of 16-bit AVR microcontrollers from Microchip and has a broad set of unique functions, such as a powerful onboard mikroProg programmer and In-Circuit debugger over USB. The development board is well organized and designed so that the end-user has all the necessary elements in one place, such as switches, buttons, indicators, connectors, and others. With four different connectors for each port, EasyAVR v7 allows you to connect accessory boards, sensors, and custom electronics more

efficiently than ever. Each part of the EasyAVR v7 development board contains the components necessary for the most efficient operation of the same board. An integrated mikroProg, a fast USB 2.0 programmer with mikroICD hardware In-Circuit Debugger, offers many valuable programming/debugging options and seamless integration with the Mikroe software environment. Besides it also includes a clean and regulated power supply block for the development board. It can use a wide range of external power sources, including an external 12V power supply, 7-12V AC or 9-15V DC via DC connector/screw terminals, and a power source via the USB Type-B (USB-B)

connector. Communication options such as USB-UART and RS-232 are also included, alongside the well-established mikroBUS™ standard, three display options (7-segment, graphical, and character-based LCD), and several different DIP sockets which cover a wide range of 16-bit AVR MCUs. EasyAVR v7 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

EasyAVR v7 horizontal image

Microcontroller Overview

MCU Card / MCU

Architecture

AVR

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

4096

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PA6
RST
External Antenna Activation
PA5
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Standby Mode
PD4
PWM
NC
NC
INT
UART TX
PD1
TX
UART RX
PD0
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

GPS 5 Click Schematic schematic

Step by step

Project assembly

EasyAVR v7 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyAVR v7 as your development board.

EasyAVR v7 front image hardware assembly
Buck 22 Click front image hardware assembly
MCU DIP 40 hardware assembly
EasyAVR v7 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 Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
EasyPIC PRO v7a Display Selection Necto Step hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image 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 GPS 5 Click driver.

Key functions:

  • gps5_set_rst_pin This function sets the RST pin logic state.

  • gps5_generic_read This function reads a desired number of data bytes by using UART serial interface.

  • gps5_parse_gngga This function parses the GNGGA data from the read response buffer.

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 GPS 5 Click Example.
 *
 * # Description
 * This example demonstrates the use of GPS 5 click by reading and displaying
 * the GPS coordinates.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and resets the click board.
 *
 * ## Application Task
 * Reads the received data, parses the GNGGA info from it, and once it receives the position fix
 * it will start displaying the coordinates on the USB UART.
 *
 * ## Additional Function
 * - static void gps5_clear_app_buf ( void )
 * - static err_t gps5_process ( gps5_t *ctx )
 * - static void gps5_parser_application ( char *rsp )
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "gps5.h"

#define PROCESS_BUFFER_SIZE 200

static gps5_t gps5;
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;

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

/**
 * @brief GPS 5 data reading function.
 * @details This function reads data from device and concatenates data to application buffer.
 * @param[in] ctx : Click context object.
 * See #gps5_t object definition for detailed explanation.
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read or Application buffer overflow.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t gps5_process ( gps5_t *ctx );

/**
 * @brief GPS 5 parser application.
 * @param[in] rsp Response buffer.
 * @details This function logs GNSS data on the USB UART.
 * @return None.
 * @note None.
 */
static void gps5_parser_application ( char *rsp );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    gps5_cfg_t gps5_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.
    gps5_cfg_setup( &gps5_cfg );
    GPS5_MAP_MIKROBUS( gps5_cfg, MIKROBUS_1 );
    if ( UART_ERROR == gps5_init( &gps5, &gps5_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    gps5_process( &gps5 );
    if ( app_buf_len > ( sizeof ( ( char * ) GPS5_RSP_GNGGA ) + GPS5_GNGGA_ELEMENT_SIZE ) ) 
    {
        gps5_parser_application( app_buf );
    }
}

void main ( void ) 
{
    application_init( );

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

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

static err_t gps5_process ( gps5_t *ctx ) 
{
    int32_t rx_size = 0;
    char rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    rx_size = gps5_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = 0;
        if ( ( app_buf_len + rx_size ) > PROCESS_BUFFER_SIZE ) 
        {
            gps5_clear_app_buf(  );
            return GPS5_ERROR;
        } 
        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_buf[ rx_cnt ] ) 
            {
                app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buf[ rx_cnt ];
            }
            else
            {
                app_buf_len--;
                buf_cnt--;
            }
        }
        return GPS5_OK;
    }
    return GPS5_ERROR;
}

static void gps5_parser_application ( char *rsp )
{
    char element_buf[ 100 ] = { 0 };
    if ( GPS5_OK == gps5_parse_gngga( rsp, GPS5_GNGGA_LATITUDE, element_buf ) )
    {
        static uint8_t wait_for_fix_cnt = 0;
        if ( strlen( element_buf ) > 0 )
        {
            log_printf( &logger, "\r\n Latitude: %.2s degrees, %s minutes \r\n", element_buf, &element_buf[ 2 ] );
            gps5_parse_gngga( rsp, GPS5_GNGGA_LONGITUDE, element_buf );
            log_printf( &logger, " Longitude: %.3s degrees, %s minutes \r\n", element_buf, &element_buf[ 3 ] );
            memset( element_buf, 0, sizeof( element_buf ) );
            gps5_parse_gngga( rsp, GPS5_GNGGA_ALTITUDE, element_buf );
            log_printf( &logger, " Altitude: %s m \r\n", element_buf );
            wait_for_fix_cnt = 0;
        }
        else
        {
            if ( wait_for_fix_cnt % 5 == 0 )
            {
                log_printf( &logger, " Waiting for the position fix...\r\n\n" );
                wait_for_fix_cnt = 0;
            }
            wait_for_fix_cnt++;
        }
        gps5_clear_app_buf(  );
    }
}

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