mansoureh*
Junior Member level 1
hi every body
i want to receive sms with module gsm sim300cz & then i read the sms and then for example i want to forward the text of sms to a number , at the first i can read the text & forward it but for the second time when i send sms until to read text it can not work, i try to solve this problem but i can not , i read most of the post, but i can not plz help me i am very unhappy,i put my code of my program ,please read it & tell me why it didnt work for the other times when i send a sms it can not read it?
#include "AT91SAM7x256.h"
#include "lib_AT91SAM7x256.h"
#include "delay.h"
#include "usart.h"
//#include "string.h"
#include "PIO.h"
#include "adc.h"
#include "lcd8bit.h"
#include <stdio.h>
void sms_send(void);
void delete(void);
int main(void){
unsigned char sms[250];
int k=0;
int i=0;
int j=0;
unsigned char b;
char Enter=13;
char Ctrlz=26;
char double_quote=34;
/*configuration lcd*/
lcd_rs(2,0x1);
lcd_e(2,0x2);
lcd_data(2,0x3fc);
lcd_clear();
/*configuration usart*/
USART(18432000,9600,0);
usart0_init();
/*configuration ADC*/
config_adc(0xff);
/*configuration pio*/
PORTA_OUTPUT=PA5;
PORTA_INPUT=PA29;
for(k=0;k<250;k++)
{
sms[k]=0;
}
printf("AT%c\n",Enter);
delay_ms(50);
printf("ATE0%c\n",Enter);
delay_ms(50);
printf("AT+CMGF=1%c\n",Enter);
delay_ms(50);
printf("AT+CPMS=%cME%c%c\n",double_quote,double_quote,Enter);
delay_ms(50);
delete();
while(1){
for(k=0;k<250;k++)
{
sms[k]=0;
}
printf("AT+CNMI=1,2,0,0,0%c\n",Enter);
delay_ms(50);
if(PINA(29)==0) /*CONDITION*/
{
printf("AT+CMGR=1%c\n",Enter);
while(j==0) {
b=getkey();
switch(b)
{
case 10:
if((sms[0]!=0)) {
j=1; }
break;
case 13:
if ((sms[0]!=0))
{
j=1;}
break;
default:
sms=b;
i++;
} /*END switch 1*/
} /*END while j=0 */
sms_send();
printf("%s%c",sms,Ctrlz);
SET_PORTA=PA5;
delay_ms(500);
RST_PORTA=PA5;
delay_ms(500);
SET_PORTA=PA5;
delay_ms(500);
RST_PORTA=PA5;
delay_ms(500);
j=0;
}
}
}
void sms_send(void)
{
char En=13;
char doubles=34;
/*read input data*/
printf("at%c",En);
delay_ms(500);
printf("AT+CMGF=1%c",En);
delay_ms(500);
printf("at+cmgs=%c09192484603%c%c",doubles,doubles,En);
delay_ms(100);
}
void delete(void)
{
char Ent=13;
printf("at%c",Ent);
delay_ms(500);
printf("AT+CMGD=1%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=2%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=3%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=4%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=5%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=6%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=7%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=8%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=9%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=10%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=11%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=12%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=13%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=14%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=15%c\n",Ent);
delay_s(2);
}
i want to receive sms with module gsm sim300cz & then i read the sms and then for example i want to forward the text of sms to a number , at the first i can read the text & forward it but for the second time when i send sms until to read text it can not work, i try to solve this problem but i can not , i read most of the post, but i can not plz help me i am very unhappy,i put my code of my program ,please read it & tell me why it didnt work for the other times when i send a sms it can not read it?
#include "AT91SAM7x256.h"
#include "lib_AT91SAM7x256.h"
#include "delay.h"
#include "usart.h"
//#include "string.h"
#include "PIO.h"
#include "adc.h"
#include "lcd8bit.h"
#include <stdio.h>
void sms_send(void);
void delete(void);
int main(void){
unsigned char sms[250];
int k=0;
int i=0;
int j=0;
unsigned char b;
char Enter=13;
char Ctrlz=26;
char double_quote=34;
/*configuration lcd*/
lcd_rs(2,0x1);
lcd_e(2,0x2);
lcd_data(2,0x3fc);
lcd_clear();
/*configuration usart*/
USART(18432000,9600,0);
usart0_init();
/*configuration ADC*/
config_adc(0xff);
/*configuration pio*/
PORTA_OUTPUT=PA5;
PORTA_INPUT=PA29;
for(k=0;k<250;k++)
{
sms[k]=0;
}
printf("AT%c\n",Enter);
delay_ms(50);
printf("ATE0%c\n",Enter);
delay_ms(50);
printf("AT+CMGF=1%c\n",Enter);
delay_ms(50);
printf("AT+CPMS=%cME%c%c\n",double_quote,double_quote,Enter);
delay_ms(50);
delete();
while(1){
for(k=0;k<250;k++)
{
sms[k]=0;
}
printf("AT+CNMI=1,2,0,0,0%c\n",Enter);
delay_ms(50);
if(PINA(29)==0) /*CONDITION*/
{
printf("AT+CMGR=1%c\n",Enter);
while(j==0) {
b=getkey();
switch(b)
{
case 10:
if((sms[0]!=0)) {
j=1; }
break;
case 13:
if ((sms[0]!=0))
{
j=1;}
break;
default:
sms=b;
i++;
} /*END switch 1*/
} /*END while j=0 */
sms_send();
printf("%s%c",sms,Ctrlz);
SET_PORTA=PA5;
delay_ms(500);
RST_PORTA=PA5;
delay_ms(500);
SET_PORTA=PA5;
delay_ms(500);
RST_PORTA=PA5;
delay_ms(500);
j=0;
}
}
}
void sms_send(void)
{
char En=13;
char doubles=34;
/*read input data*/
printf("at%c",En);
delay_ms(500);
printf("AT+CMGF=1%c",En);
delay_ms(500);
printf("at+cmgs=%c09192484603%c%c",doubles,doubles,En);
delay_ms(100);
}
void delete(void)
{
char Ent=13;
printf("at%c",Ent);
delay_ms(500);
printf("AT+CMGD=1%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=2%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=3%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=4%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=5%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=6%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=7%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=8%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=9%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=10%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=11%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=12%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=13%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=14%c\n",Ent);
delay_ms(500);
printf("AT+CMGD=15%c\n",Ent);
delay_s(2);
}