Discussion in "Embedded GSM Development" started by    hardikgupta21    Mar 3, 2013.
Sun Mar 03 2013, 05:00 pm
#1
im trying to extract the stored msg in sim card
im using gsm sim300 and p89v51rd2
following is the code i have written. im using serial interrupt method
im using serial communication to send AT commands to both modem and hyperterminal(i have used two max circuit, one for each)

CODE:
#include<p89v51rx2.h.txt>
#include<string.h>
unsigned char check,str[15],m,p,length;

void init_serial() // Initialize serial port
{
TMOD=0x20; // Mode2
TH1=0xfd; // 9600 baud
SCON=0x50; // Serial mode=1 ,8-Bit data,1 Stop bit ,1 Start bit, Receiving on
TR1=1; // Start timer
}

void delay(unsigned int count)
{
unsigned int i;
while(count) {
i = 115;
while(i>0) i--;
count--;
}
}



void transmit_data(unsigned char str) // Function to transmit data through serial port
{
EA=0;
SBUF=str; //Store data in SBUF
delay(10);
while(TI==0); //Wait till data transmits
TI=0;
EA=1;
}
void string(unsigned char text[])
{
while(text[p] != '\0')
{
transmit_data(text[p]);
delay(200);
p++;
}
}

void receive_data() interrupt 4 // Function to recieve data serialy from RS232 into microcontroller
{

str[count++]=SBUF; //Read SBUF
RI=0;
}


void read(unsigned char msg[])
{
length=strlen(msg);
while(m<length)
{ EA=0;
SBUF=msg[m];
delay(1);
while(TI==0);
TI=0;
m++;
EA=1;
}
}

void main()
{
count=0;
m=0;
p=0;
init_serial(); // Initialize serial port
delay(50);
IEN0=0x90;
string("AT\r");
delay(1000);
read(str);
string("AT+CMGF=1");
delay(1000);
read(str);

}

PROBLEM:
when i send 'AT' this gets displayed on hyper 'AT' den 'OK'.. which is perfect as it shud be
but den wen m trying to send the next set of at commands following is wat i see on hyper
"+CMGF=1"... manytimes only "C" and d loop gets repeated
wat cud be d problem


[ Edited Sun Mar 03 2013, 05:02 pm ]
Mon Mar 04 2013, 11:25 am
#2
post your schematic first.
Mon Mar 04 2013, 11:06 pm
#3
im trying to implement this circuit. today i tried again. im able to send d commands but im not getting any interrupt(response from modem) here is d code which i have implemented today

CODE:
#include<p89v51rx2.h.txt>
#include<string.h>
unsigned int m, length,j;
unsigned char abc,i;
unsigned char str[250],p,x;

void init_serial() // Initialize serial port
{
abc=0;
m=0;
p=0;
x=0;
TMOD=0x20; // Mode2
TH1=0xfd; // 9600 baud
SCON=0x50; // Serial mode=1 ,8-Bit data,1 Stop bit ,1 Start bit, Receiving on
TR1=1; // Start timer
for(j=0;j<250;j++)
str[j]=0;
}

void delay(unsigned int count)
{
unsigned int i; // Keil v7.5a
while(count)
{
i = 115;
while(i>0)
i--;
count--;
}
}
void transmit_data(unsigned char str) // Function to transmit data through serial port
{
EA=0;
SBUF=str; //Store data in SBUF
delay(10);
while(TI==0); //Wait till data transmits
TI=0;
EA=1;
}
void string(unsigned char text[])
{
while(text[p] != '\0')
{
transmit_data(text[p]);
delay(200);
p++;
}
}

void receive_data() interrupt 4 // Function to recieve data serialy from RS232 into microcontroller
{

str[abc]=SBUF; //Read SBUF
abc++;
RI=0;

}



void read(unsigned char msg[])
{
length=strlen(msg);
while(m<length)
{
EA=0;
SBUF=msg[m];
while(TI==0);
TI=0;
m++;
EA=1;
delay(100);

}
}
void clear()
{
for(j=0;j<250;j++)
str[j]=0;
}

void main()
{
IEN0=0x90;
init_serial(); // Initialize serial port
string("AT\r");
delay(2000);
read(str);
abc=0;
p=0;
clear();
delay(1000);
string("AT+CMGF=1\r\n");
delay(2000);
read(str);
p=0;
abc=0;
clear();
delay(1000);
string("AT+CNMI=2,1,0,0,0\r\n");
delay(2000);
p=0;
abc=0;
string("AT+CMGR=1\r\n");
delay(3000);
read(str);
delay(1000);
}

im getting a response like this
AT
AT+CMGF=1
AT+CNMI=2,1,0,0,0
AT+CMGR=1
...and den d entire loop gets repeated. i feel my gsm is not interrupting muc

Mon Mar 04 2013, 11:09 pm
#4
in the above circuit m not using lcd to check my output. i m checking my output on hyperterminal. i have used two separate max circuits. muc is sending d commands to both terminal nd modem. also sir today wen i implemented the above for few times i got output d way it shud be after i excute "AT+CMGR=1". But this very few times. d rest of the time it showed either garbage value or no value.


[ Edited Mon Mar 04 2013, 11:09 pm ]
Tue Mar 05 2013, 10:19 am
#5
thats the reason I want to see how you have connected two MAX232 circutis. coz you cannot short two TX lines. however you can short RX lines. So I would like to see how two max232 are connected so that we can find the actual problem.
Wed Mar 06 2013, 07:17 pm
#6
SIR im attaching my schematic
im using crystal frequency of 22.1184mhz coz ahead im displaying my result(extracted msg) on 30*7 scrolling board
sir the problem im facing now is the response is not interrupting the microcontroller. and if ever it's doing im getting only the AT commands sent by micro. not the actual response which starts like
+CMGR: REC UNREAD .....
pls help sir.

Thu Mar 07 2013, 12:47 pm
#7
to see modem's response you need to connect modem's tx to PC. You can use T2In for modem's input and you can switch between microcontroller and modem then and see if they are responding properly or not.

one more think surprised me is "unsigned char str[250]" you are using 250 byte array Are you able to build it? what build model you configured in project properties?

In your interrupt function, you are not checking for TI or RI as both tx,rx interrupts of uart are shared. You need to check for appropriate flag and only then clear it. and instead of using TI directly in your code use TI_flag variable which you can set in your ISR when you get TI interrupt. Please make necessary changes to actually get things working.
Fri Mar 08 2013, 04:39 pm
#8
sir i can't connect my modem directly to pc is becoz i want to filter my op of modem after AT+CMGR=1 and den send d msg. also sir wat do u mean by switch between micro and modem?
sir my buffer size is 250. i have kept dis to be on safe side irrespective how long my message response is from modem. i have changed my model from 'small' to large. dis done using keil.
also sir can u pls explain wid an eg how shud i make my interrupt func better?


[ Edited Fri Mar 08 2013, 04:41 pm ]
Fri Mar 08 2013, 06:08 pm
#9
I am not saying directly connect your modem to pc, rather I am saying you can monitor both command from controller and response from modem at the same time by tapping tx pins of controller (which you already did) and modem.

in interrupt function you can do modification like this:
void receive_data() interrupt 4
{
    if (RI == 1) {
        // process receive interrupt
        RI = 0;
    } else {
        // its a tx interrupt
        TI = 0;
        TI_flag = 1;
        // create a variable with this name and check for TI_flag instead of TI
    }
}
Sat Mar 09 2013, 08:26 am
#10
sir but modem transmits on rx pin and receives on tx pin right?

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

chimichmedic1204
Sun May 05 2024, 11:06 am
Jamiegob
Sun May 05 2024, 10:11 am
Gregoryjed
Sun May 05 2024, 10:02 am
Mariocax
Sun May 05 2024, 08:51 am
WilliamErync
Sun May 05 2024, 02:35 am
Danielnof
Sat May 04 2024, 11:12 pm
oriminna
Sat May 04 2024, 08:28 pm
scaneraNom
Sat May 04 2024, 02:21 am