Screenshot 1:
// GSM MODULE INIT
gsm_cmdSingle( “AT” ); //are you there?
gsm_cmdSingle( “AT” );
gsm_cmdSingle( “AT” );
gsm_cmdSingle( “ATE0” ); //turn off echo
gsm_cmdSingle( “AT+CMGF=1” ); //text
messaging
// SMS message
msg[0] = ‘\0’;
strcat(msg, “Text Message from Design Cycle”);
strcat(msg, “\r\n”); // Add new line (CR + LF)
}
/***********************************************
//* HANDLER FOR DATA SENT FROM GSM MODULE UART
//***********************************************
void gsm_default_handler( uint8_t *rsp, uint8_t
*evArgs )
{
mikrobus_logWrite( rsp, _LOG_TEXT );
// SKIP <CR> and <LF>
if (0 == strncmp(“RING”, rsp + 2, 4))
{
callFlag = 1;
}
}
//***********************************************
//* APPLICATION INIT
//***********************************************
void applicationInit()
{
// GSM TIMER INIT
gsm_configTimer();
The timer configuration is easily accomplished using
a MikroElektronika application called Timer Calculator
(Screenshot 2), which is free for download. As you can see
in Screenshot 2, the timer tick is set for one millisecond.
The GSM click is attached to the mikroBUS1 GPIO
and UART pins using the gsm_uartDriverInit function,
which is part of the GSM click library. The (T_GSM_P)
is nothing more than a type, which is defined as a byte
pointer in the Click_GSM_types.h file (#define T_GSM_P
const uint8_t*).
The default handler is responsible for logging the click
UART responses and filtering out the RING indication for
incoming calls. The 1500 argument of the gsm_coreInit
function call is a watchdog timeout value.
// GSM DRIVER INIT
gsm_uartDriverInit((T_GSM_P)&_MIKROBUS1_GPIO,
(T_GSM_P)&_MIKROBUS1_UART);
gsm_coreInit( gsm_default_handler, 1500 );
Following the enabling of hardware flow control
(gsm_hfcEnable(true)), we power-up the GSM module and
issue some AT commands. The AT commands insure that
the GSM click hears us, turns off echo, and sets up for
text messaging. Finally, our SMS (Short Message Service)
message is defined and we’re ready to rock and roll.
// GSM MODULE POWER ON
gsm_hfcEnable( true );
gsm_modulePower( true );
The application task is designed to answer the phone,
immediately hang up, and three seconds later send our
predetermined text message:
//***********************************************
//* APPLICATION TASK
//***********************************************
void applicationTask()
{
// CORE STATE MACHINE
gsm_process();
if (0 != callFlag)
{
gsm_cmdSingle( “ATH” );
Delay_ms( 3000 );
sendSMSmsg(msg);
callFlag = 0;
}
n SCREENSHOT 2. This handy little app does
all of the dirty work and generates a skeleton
timer interrupt handler to boot. The preset I
selected happened to match the original code.
However, you don’t have to use the presets
and can enter your own timer configuration
values.
May/June 2018 73