Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interfacing GSM modem with Zilog

Status
Not open for further replies.

reynn

New Member
Hello there! I am currently working on a home automation system used to monitor and control(ON/OFF) appliances. Problem is its my first time programming using a GSM modem, im not sure how to use the at commands in z8, though i have read users using PIC microcontrollers doing it. Please help! If you have a guide program that uses AT commands it would be greatly appreciated.. :D
 
I used the Z8 with built in basic back in 1982. :)

The AT modem commands are for the modem. They remain the same regardless of what processor you use to control it.

Issue modem commands using the language you are using. Without knowing what that language it is, it is not possible to give further help.

It is a good idea to post the code you want help with.

3v0
 
Im still working with the program.. And im currently using, ZDS II Z8Encore ver 4.9.6. And when i mean working "I dont know where to start with the AT commands"
 
Im still working with the program.. And im currently using, ZDS II Z8Encore ver 4.9.6. And when i mean working "I dont know where to start with the AT commands"

In the first post you said "my cow is ill"
In this post you said "my cow is ill and I have a barn"

Without a crystal ball how can anyone help you ?

What language are you using to write your program?
Do you know how to progam using it ?
What experiance do you have programming ?

Without the code you have so far and the schematic so we can know how the modem is connected to the Z8 it is not possible to provide helpful help.


3v0
 
Oh is that what I said? Funny.. Anyway, im using C language, and yes i am capable enough to program using this. And yes i have an ample amount of experience in programming. And about the code, i cant provide it because i dont know where to start because of the usage of AT commands which I am not familiar with sadly. And the schematic? I'll post it or pm it later because i am not using my computer. And forgive me for making it sound like my cow is ill, im still a noob when it comes to this.
 
Oh is that what I said? Funny.. Anyway, im using C language, and yes i am capable enough to program using this. And yes i have an ample amount of experience in programming. And about the code, i cant provide it because i dont know where to start because of the usage of AT commands which I am not familiar with sadly. And the schematic? I'll post it or pm it later because i am not using my computer. And forgive me for making it sound like my cow is ill, im still a noob when it comes to this.

hi reynn,

Look thru these links:
Send SMS using AT commands
GPRS / SMS
Receiving SMS messages using AT commands
**broken link removed**
 
No problem.

This sentance "im not sure how to use the at commands in z8," caused me to doubt your skill. Had you said "m not sure how to use the at commands" I would have done as Erick did and provide links.

At this point there is no need for code or schematics. If you do have problems with the code they will be needed.

Good luck.

3v0
 
Last edited:
hi reynn,
Ref your Pm's.
Do you have an external modem that you could use for a test with your PC and a laptop.?
 
im not using my computer right now.. I'll reply when im using my pc. The GSM modem module is there.
 
im not using my computer right now.. I'll reply when im using my pc. The GSM modem module is there.

OK,

These links have some AT code examples.

SMS Tutorial: Result Codes of AT Commands. The OK and ERROR Final Result Codes
SMS Tutorial: How to Receive SMS Messages Using a Computer/PC through a Mobile Phone or GSM/GPRS Modem? AT Commands
i can't recieve information from gsm modem : 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes

BTW: it would be best for other members reading this thread, to ask questions here rather than PM requests to me.
Without the context of your questions the reply is meaningless.:)
 
hello, i am currently working on this program for home automation using GSM modem. So far i currently have the +CMGS command working in the program, but i am currently having great difficulty in the +CMGR command. Do you maybe have a sample function using this AT command and in C language?

Heres a link of the sample program that i am working on, ZDS II:

Free file hosting by Savefile.com

An apology to sir 3v0 for me not following the rules..
 
Please help! in the at_cmgl function it keeps looping back. I dont know whats going with this, all other functions work but the at_cmgl doesnt. Please can anyone tell me whats wrong with my at_cmgl function?

Program:
#include <ez8.h>
#include <sio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define TESTING 0
#define MSG_LEN 250

unsigned int msg_index,info_index;
// const unsigned int SIM=40;
char msg[MSG_LEN],cnum[]="+xxxxxxxxxxx"; //cnum is the target number for sending SMS



void clear_msg(void){ //clear string for storage

int i;

for(i=0;i<MSG_LEN;i++) msg='\0';
msg_index=0;

}


void delay(int loop){ // software delay

int i,j,k;

for (i=loop; i>=0; i--) for (j=0;j<0xFF;j++) for (k=0;k<0xFF;k++);

}

void init_port(void){

PCDD &= ~0xFF; // set Port C as output
PCAF &= ~0xFF; // set alternate function off
PCOC &= ~0xFF; // push-pull mode
PCHDE |= 0xFF; // high drive enabled

PBDD |= 0xFF; // set Port B as input
PBAF &= ~0xFF; // set alternate function off

PDDD &= ~0x03; //set data direction to output
PDAF &= ~0x03; //turn alternate function off
PDOC &= ~0x03; //set output control to push-pull
PDHDE |= 0x03; //set high-drive enable on
PDOUT |= 0x03; //set initial output to high

}

#pragma interrupt // UART0 interrupt service routine
void read_uart0(void){

if (U0STAT0 & 0x80) msg[msg_index++]=U0RXD; //Read UART Register and store in a character array

}

void initial_uart0(void){ //UART0 for GSM MODULE (PA4:RX, PA5;TX)

DI();
SET_VECTOR(UART0_RX, read_uart0);
IRQ0ENH |= 0x10;
IRQ0ENL |= 0x10;
IRQ0 &= ~0x10;
U0CTL1 &= ~0x02;
EI();

}


void at_at(void){ //Test for response

select_port(_UART0);
clear_msg();
printf("AT\n");
delay(1);
if(TESTING){select_port(_UART1); printf("%s", msg); }
delay(1);

}

void at_cnmi(int setting){ //Set new message indications

do{
select_port(_UART0);
clear_msg();
printf("AT+CNMI=2,%d,0,0,0\n",setting);
delay(1);
if(TESTING){select_port(_UART1); printf("%s", msg); }
delay(1);
}while(strstr(msg,"ERROR")!=NULL); //Sometimes the module will return an ERROR even if the command is valid.
//Loop until command is accepted
}

void init_gsm(void){ //Initialize GSM module

delay(20); //Delay for GSM module boot up
PBOUT |= 0x01; //Trigger GSM module to power up
delay(20);
PBOUT &= ~0x01;
delay(1);

at_at();

do{
select_port(_UART0);
clear_msg();
printf("AT+CFUN=1\n"); //Set GSM module functionality to full
delay(1);
if(TESTING){select_port(_UART1); printf("%s", msg); }
delay(1);
}while(strstr(msg,"ERROR")!=NULL); //Check if in ERROR; if in ERROR, try again

at_at(); //Sometimes, GSM module could not recognize the next command, so an AT is buffered here

do{
select_port(_UART0);
clear_msg();
printf("AT+CMGF=1\n"); //Set message format to text
delay(1);
if(TESTING){select_port(_UART1); printf("%s", msg); }
delay(1);
}while(strstr(msg,"ERROR")!=NULL);

do{
select_port(_UART0);
clear_msg();
printf("AT+CSDH=0\n"); //Disable detailed SMS header
delay(1);
if(TESTING){select_port(_UART1); printf("%s", msg); }
delay(1);
}while(strstr(msg,"ERROR")!=NULL);

do{
select_port(_UART0);
clear_msg();
printf("AT+COPS=0\n"); //Check service provider signal availability
delay(1); //Wait for reply
if(TESTING){select_port(_UART1); printf("%s", msg); }
delay(1);
}while(strstr(msg,"ERROR")!=NULL); //Will loop forever if no service provider signal is available

do{
select_port(_UART0);
clear_msg();
printf("AT+CPMS=\"SM\",\"SM\",\"SM\"\n"); //Set preferred memory storage (to SIM)
delay(1);
if(TESTING){select_port(_UART1); printf("%s", msg); }
delay(1);
}while(strstr(msg,"ERROR")!=NULL);

//at_cnmi(0); //Set new message indications (Disabled)
clear_msg();

}

void at_cmgs(char *data){ //Function for sending SMS

at_at();

do{
clear_msg();
select_port(_UART0);
printf("AT+CMGS=\"%s\"\n",cnum);
delay(1);
//if (TESTING) {select_port(_UART1); printf("%s",msg);}
delay(1);

clear_msg();
select_port(_UART0);
printf("%s",data); putch(0x1A);
//while(strstr(msg,"ERROR")==NULL && strstr(msg,"OK")==NULL)
delay(1); //Wait for reply
//if (TESTING) {select_port(_UART1); printf("%s",msg);}
delay(1);
}while(strstr(msg,"ERROR")!=NULL); //Resend SMS if sending failed
clear_msg();

}

void relay1_on(){
PDOUT |= 0x01; //PD0 is ON(HIGH)
at_cmgs("LED D0 is ON");
}

void relay2_on(){
PDOUT |= 0x02; //PD1 is ON(HIGH)
at_cmgs("LED D1 is ON");
}

void relay1_off(){
PDOUT &= ~0x01; //PD0 is OFF(LOW)
at_cmgs("LED D0 is OFF");
}

void relay2_off(){
PDOUT &= ~0x02; //PD1 is OFF(LOW)
at_cmgs("LED D1 is OFF");
}

void relayall_on(){
PDOUT |= 0x01;
PDOUT |= 0x02; //PD0&1 are ON
at_cmgs("LED D0 & D1 are ON");
}

void relayall_off(){
PDOUT &= ~0x01;
PDOUT &= ~0x02; //PD0&1 are OFF
at_cmgs("LED D0 & D1 are OFF");
}

void delete_msg(){

select_port(_UART0);
clear_msg();
printf("AT+CMGD=1\n");
while(strstr(msg,"OK")==NULL) delay(1);
}

void at_cmgl(void){ //Function for receiving sms

at_at();
do
{
clear_msg();
select_port(_UART0);
//printf("AT+CMGL=\"ALL\"\n");
printf("AT+CMGR=1\n");
delay(10); //Wait for reply
}while(strstr(msg,"OK")==NULL); //Will loop forever if no incoming msg

if(strstr(msg,"low")!=NULL)
PDOUT |= 0x01;
else if (strstr(msg,"hi")!=NULL)
PDOUT &= ~0x01;

/*else if (strstr(msg,"LED D1 ON")!=0)
relay2_on();
else if (strstr(msg,"LED D1 OFF")!=0)
relay2_off();
else if (strstr(msg,"ALL LED ON")!=0)
relayall_on();
else if (strstr(msg,"ALL LED OFF")!=0)
relayall_off();*/
else delete_msg();
delay(1);

}

void main(void){

init_uart(_UART0, _DEFFREQ, _DEFBAUD); //UART0 for GSM MODULE (PA4:RX, PA5;TX)
// init_uart(_UART1, _DEFFREQ, _DEFBAUD); //UART1 for DAUGHTER SLIMBOARD or DEBUG (serial cable)

init_port();
initial_uart0();
init_gsm();
//initial_uart1(); //Data Logging part not yet integrated
//at_cmgs("Initialization Complete");


at_cmgl();
delay(1);

}
 
Hi everyone, I saw the code posted above and I am trying to learn AT programming by deciphering your code. Anyway, albeit this thread is quite old, I hope somebody will reply to my question:

In the code above:

void at_at(void){ //Test for response

select_port(_UART0);
clear_msg();
printf("AT\n");
delay(1);
if(TESTING){select_port(_UART1); printf("%s", msg); }
delay(1);

}

I saw the if(TESTING){select_port(_UART1); printf("%s", msg); } line, but TESTING is defined as '0' above right? so meaning this part of the code will always be bypassed since it won't become true no matter what? Then why is that part of the code still placed there? Can anybody help me here? thanks
 
Last edited:
It's a debug flag. You put the print statements in the code so it tells you what is happening. You enable/disable them with a #define. You only have to edit one line when you don't want it to print anymore.
 
^ok thanks.

Another question, I tried modifying the program to some extent that it can send simple text messages, I'm quite new in C-Embedded AT-Codes. I get an error with this line (in BOLD)


#pragma interrupt // UART0 interrupt service routine
void read_uart0(void){

if (U0STAT0 & 0x80) msg[msg_index++]=U0RXD; //Read UART Register and store in a character array

}

void initial_uart0(void){ //UART0 for GSM MODULE (PA4:RX, PA5;TX)

DI();
SET_VECTOR(UART0_RX, read_uart0);
IRQ0ENH |= 0x10;
IRQ0ENL |= 0x10;
IRQ0 &= ~0x10;
U0CTL1 &= ~0x02;
EI();

}


I know that these parts correspond to interrupts, and here are my questions:

1. what do the parameters U0STAT0, U0RXD, and U0CTL1 mean?
2. why does the program need to have these interrupt lines?
3. can you suggest any book (or downloadable ebook) that can teach me C-Embedded AT Commands? I always just try to understand thing by example, and its quite time consuming.
4. why do I get error with the U0CTL1 part?

Thanks a lot to those who will answer
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top