By the end of this post, you will know how to receive an SMS from Hexiwear. You’ll need three things: Hexiwear, GSM 4 click, and the Hexiwear docking station.

GSM 4 click is the latest of the GSM communication click boards. Like its predecessor 3G SARA, it carries a u-blox module.

The difference between these two click boards is that GSM 4 supports 2.5G and 3G SARA supports 2.75G. You can get more information about GSM generations on our previous post. But this is not the only difference, when it comes to these click boards — GSM 4 click has an internal audio codec, while 3G SARA click has a separate onboard IC for the audio codec.

In this article, we will focus on using the GSM 4 click with the Hexiwear docking station.

GSM 4 click

Before we begin it’s important to mention that GSM 4 has global quad-band coverage. The 900MHz and 1800MHz frequencies are used in most parts of the world (Europe, Africa, Middle East, Asia). The 850MHz and 1900MHz are used in North, South and Central America.

You can find more information about this click board on the GSM 4 click product page.


What do we need

We have used mikroC PRO for ARM compiler and the AT Parser library in this code example. The AT Parser library has already been explained in one of our previous posts. The OLED click library has also been used in this example, and you can find it on the official Hexiwear repository. All the images used in the example are generated by using Visual TFT.

You may already know, but for an application that uses AT Parser you need to initialize the UART interrupt and correctly define the ISR function that feeds data it gets from the modem to the parser — in this case, that would be the GSM 4 click. To initialize the UART interrupt on NXP’s MK64 microcontrollers it is enough to edit just one registry and enable the ISR.

UART2_C2 |= 1 << 5;

The interrupt routine is also really simple, as you can see:

     char foo = UART2_S1;
     char tmp = UART2_D;

     if( foo & ( 1 << 5 ) )
        dev_rx( tmp );

The foo variable detects the event caused by the interrupt. To be more precise, the fifth bit will be set, if the interrupt is generated by excepting a new character. Variable tmp variable is actually a character that we got from the GSM 4 click.

If you take a closer look at our example, you are bound to notice that two more UART modules are initialised, and one more UART interrupt. The UART3 is used for logging data on the mikroBUS 2 docking station. For communication between KW40 and MK64, if it is necessary, UART4 is used. The KW40 is used to send data to UART3 of the MK64 microcontroller. This is how the cap-sense buttons on the front side of Hexiwear are controlled.

The application sends a predefined SMS on a phone number you set.

void gsm4_send_sms( uint8_t* rsp, uint8_t rsp_len )
    at_cmd( "AT+CMGS=\"0643280993\"" );
    at_cmd_addition( "Hello it's me, Hexiwear! :)" );
    sent_f = true;

We set flag sent_f so we can later call an image from the main function, as a confirmation that the SMS was successfully sent.

void main() {

    add_event_handler( PT_PRESS_LEFT, gsm4_send_sms );
    OLED_DrawImage( gsm_4_bmp, 0 , 0 );
    LED3 = 1;
    while( 1 ) 
        if( ring_f ) 
             LED3 = ~LED3;
             ring_f = false;
        if( sent_f )
            OLED_DrawImage( msg_sent_bmp, 0 , 0 );
            Delay_ms( 1500 );
            OLED_DrawImage( gsm_4_bmp, 0 , 0 );
            sent_f = false;

The result of this demo is a rather simple application you can upgrade if you want and add new functions. Maybe it can give you an idea for a new application with AT Parser on Hexiwear.


You can use this demo with other GSM click boards as well, by making minor changes to the source code. The GSM 4 click can also be used on any Mikroelektronika development board, thanks to the compilers and libraries.
We invite you to use this demo and create your own project.

Hexiwear official web site

Learn article

u-blox official web site

Source code on GitHub

Libstock libraries

EasyPIC v7 development board

GSM 4 click

All offers in one place

About Author : Lana Vulic

Add comment