PIC to MAX232

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
So how does this work....this has more 's' then the other one.

C:
void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, char *s8, unsigned int *idx, char *gsmAttempt, char clr) {
    asm clrwdt

    while(strstr(s1, CopyConst2Ram(s2, s3)) == 0) {
        asm clrwdt
        GSM_Send_Const_Command(s1, s2, s3, s5, idx, gsmAttempt, 1);
        GSM_Send_Const_Command(s1, s2, s3, s6, idx, gsmAttempt, 1);
        GSM_Send_Const_Command(s1, s2, s4, s7, idx, gsmAttempt, 1);

        UART1_Write_Text(s8);
        Delay_ms(500);
        UART1_Write(0x1A);

        DelayXSec(6);
    }

    memset(gsmBuffer, '\0', sizeof(gsmBuffer));
    (*idx) = 0;
    asm clrwdt
}
From your code I can see

C:
sbit sendSmsFlag at myFlags.B0;
char sms[30];
char smsIndex[4];
const char sms1[] = "LED is ON";
const char sms2[] = "LED is OFF";
const char sms3[] = "Invalid Command Received";
These are so far I see from your code..
But how you send the SMS is confusing.o_O
I have no idea how this is done...:confused:
 

bwack

Joined Nov 15, 2011
113
It helps to include the statement which calls this function also, but actually it would be nice to call s1 s2 something more self explainatory. Now I realise I don't have the calling statement for Send_SMS, but at least this is related:
Code:
     case Send_AT: // Send AT and check for AT\r\n\r\n
       GSM_Send_Const_Command(GSM_Buffer, buffer1, ATR11, ATC00, \
                             &gsmBufferIndex, &GSM_Attempt, 0);
 

jayanthd

Joined Jul 4, 2015
945
See this.

C:
char gsmBuffer[270];
char message[50];
char buffer1[50];
char buffer2[50];
char sms[100];
char smsIndex[4];
char value[4];
char str[23];
char lightDelayCode[10];
char temperatureThresholdData[5];
char gsmAttempt = 0;
char port = 0;
unsigned int diff = 0;

unsigned int iTemperature = 0, iPreviousTemperature = 0;
unsigned int iTemperatureThreshold = 0;
unsigned int delayCounter = 0, lightBlinkCounter = 0;
unsigned long lightDelayValue = 0, noOf200MilliSecondsCounter = 0, gsmBufferIndex = 0;
unsigned int addr = 0, val = 0;
unsigned char iEvent = 15;
unsigned int mainsVoltage = 0, prevMainsVoltage = 0;

double fTemperature = 0.0, fPreviousTemperature = 0.0;

//GSM Constant Strings
const char atCommand1[] = "AT\r";
const char atCommand2[] = "ATE0\r";
const char atCommand3[] = "ATE1\r";
const char atCommand4[] = "AT+IPR=9600\r";
const char atCommand5[] = "AT+CMGF=1\r";
const char atCommand6[] = "AT+CPMS=\"SM\",\"SM\",\"SM\"\r";
const char atCommand7[] = "AT+CNMI=2,1\r";
const char atCommand8[] = "AT+CMGR=";
//const char atCommand9[] = "AT+CMGS=\"9900516837\"\r";
const char atCommand9[] = "AT+CMGS=\"+27725138668\"\r";
const char atCommandA[] = "AT+CMGD=1,4\r";

const char atResponse1[] = "\r\nOK\r\n";
const char atResponse2[] = "ERROR";
const char atResponse3[] = "+CMTI: \"SM\",";
const char atResponse4[] = "> ";
const char atResponse5[] = "RING";
const char atResponse6[] = "NO CARRIER";
const char atResponse7[] = "NO ANSWER";
const char atResponse8[] = "+CFUN: 1";
const char atResponse9[] = "+CPIN: READY";



const char secretCode[]  = "20!4";
const char secretCode0[] = "20!4#l1";  //to turn lights ON
const char secretCode1[] = "20!4#l0";  //to turn lights OFF
const char secretCode2[] = "20!4#ls";  //to get STATUS of lights
const char secretCode3[] = "20!4#gt";  //to get temperature reading
const char secretCode4[] = "20!4#da";  //to de-activate the alarm
const char secretCode5[] = "20!4#aa";  //to activate the alarm
const char secretCode6[] = "20!4#as";  //to get the STATUS of the alarm
const char secretCode7[] = "20!4#cg";  //to close the electric gate
const char secretCode8[] = "20!4#og";  //to open the electric gate
const char secretCode9[] = "20!4#gs";  //to get the STATUS of the electric gate to see if its OPEN/CLOSED
const char secretCodeA[] = "20!4#ps";  //to get the STATUS of the power supply if its interrupted or not
const char secretCodeB[] = "20!4#rt";  //to get set temperature thtreshold value
const char secretCodeC[] = "20!4#d";   //to set Light On / OFF Delay
const char secretCodeD[] = "20!4#t";   //to set Light On / OFF Delay

const char sms1[] = "Light is ON";
const char sms2[] = "Light is OFF";
const char sms3[] = "Gate is open";
const char sms4[] = "Gate is closed";
const char sms5[] = "Alarm is ON";
const char sms6[] = "Alarm is OFF";
const char sms7[] = "Temperature is high";
const char sms8[] = "Power supply is OK";
const char sms9[] = "Power supply is not OK";
const char smsA[] = "Temperature Threshold is set to ";
const char smsB[] = " degree C";
const char smsC[] = "Temperature is ";
const char smsD[] = "Cannot control Gate. Voltage is not Ok";
const char smsE[] = "Incorrect Code Received";
const char smsF[] = "Light Will Turn ON after ";
const char smsG[] = "Light will turn OFF after ";
const char smsH[] = " minutes";
const char smsI[] = "First time use. ";
const char smsJ[] = " Threshold is not set.";

//Function Prototypes
char *CopyConst2Ram(char *dest, const char *src);

void DelayXSec(unsigned long int sec);

char *CopyConst2Ram(char *dest, const char *src);
void GSM_RESET();
void Extract_SMS(char *s1, char *s2);
void Get_SMS_gsmBufferIndex(char *s1, char *s2);
void Get_GSM_Time(char *s1, char *s2);
void Get_Code(char *s1, char *s2);
void GSM_Send_Const_Command(char *s1, char *s2, const char *s3, const char *s4, unsigned int *idx, char *gsmAttempt, char clr);
void GSM_Get_SMS(char *s1, char *s2, const char *s3, const char *s4, char *s5, unsigned int *idx, char *gsmAttempt, char *s6, char clr);
void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, char *s8, unsigned int *idx, char *gsmAttempt, char clr);

#define SEND_AT_COMMAND GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand1, &gsmBufferIndex, &gsmAttempt, 1);
#define SET_GSM_BAUDRATE  GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand4, &gsmBufferIndex, &gsmAttempt, 1);
#define SET_GSM_TEXT_MODE GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand5, &gsmBufferIndex, &gsmAttempt, 1);
#define SET_SIM_MEMORY_FOR_SMS GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand6, &gsmBufferIndex, &gsmAttempt, 1);
#define ENABLE_NEW_SMS_NOTIFICATION GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand7, &gsmBufferIndex, &gsmAttempt, 1);
#define DELETE_ALL_SMS GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommandA, &gsmBufferIndex, &gsmAttempt, 1);
#define READ_SMS GSM_Get_SMS(gsmBuffer, buffer1, atResponse1, atCommand8, smsIndex, &gsmBufferIndex, &gsmAttempt, sms, 1);
#define SEND_SMS Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
@bwack
@jayanthd code does not have any SMS sending routine beside the function in post #182.
I too was thinking of doing what you @bwack said.
But I thought @jayanthd might have a simple method...I dunno.

I cannot have the sending SMS function use too much memory as I am approaching the limit of the pace I have left in main code which I need the Modem code to be written.
I decided to keep the SMS short due to this reason.
for now I have something like this
C:
const char SMS1[]  = "Modem Check.";
const char SMS2[]  = "xxxxx Error Detected!";
const char SMS3A[] = "xxxx1 Failure!";
const char SMS3B[] = "xxxx1 Warning!";
const char SMS3C[] = "xxxx1 Alarm!";
const char SMS4A[] = "xxxx2 Failure!";
const char SMS4B[] = "xxxx2 Warning!";
const char SMS4C[] = "xxxx2 Alarm!";
Above are the SMS I need to send, One at any occasion and below are the no. that I need to send.
C:
const char Ph1[]   = "AT+CMGS=\"+960xxxxxxx\"\r\n"; //
const char Ph2[]   = "AT+CMGS=\"+960xxxxxxx\"\r\n"; //
const char Ph3[]   = "AT+CMGS=\"+960xxxxxxx\"\r\n"; //
const char Ph4[]   = "AT+CMGS=\"+960xxxxxxx\"\r\n"; //
const char Ph5[]   = "AT+CMGS=\"+960xxxxxxx\"\r\n"; //
Our no.s have 7 characters not including "+960" which is the international code ..so 11 characters
C:
char SMS[22];
I set the above for 22 characters as the max SMS size is "21" and I added an extra for NULL.

The phone no.s 5. but I might not be using all of 'em as I was told to accommodate for 5 no.s max.
One SMS will be sent at any given time to all no.s most of the time.

PS. The "X"'s is the above code is needed for privacy reasons.
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
See this.

C:
char gsmBuffer[270];
char message[50];
char buffer1[50];
char buffer2[50];
char sms[100];
char smsIndex[4];
char value[4];
char str[23];
char lightDelayCode[10];
char temperatureThresholdData[5];
char gsmAttempt = 0;
char port = 0;
unsigned int diff = 0;

unsigned int iTemperature = 0, iPreviousTemperature = 0;
unsigned int iTemperatureThreshold = 0;
unsigned int delayCounter = 0, lightBlinkCounter = 0;
unsigned long lightDelayValue = 0, noOf200MilliSecondsCounter = 0, gsmBufferIndex = 0;
unsigned int addr = 0, val = 0;
unsigned char iEvent = 15;
unsigned int mainsVoltage = 0, prevMainsVoltage = 0;

double fTemperature = 0.0, fPreviousTemperature = 0.0;

//GSM Constant Strings
const char atCommand1[] = "AT\r";
const char atCommand2[] = "ATE0\r";
const char atCommand3[] = "ATE1\r";
const char atCommand4[] = "AT+IPR=9600\r";
const char atCommand5[] = "AT+CMGF=1\r";
const char atCommand6[] = "AT+CPMS=\"SM\",\"SM\",\"SM\"\r";
const char atCommand7[] = "AT+CNMI=2,1\r";
const char atCommand8[] = "AT+CMGR=";
//const char atCommand9[] = "AT+CMGS=\"9900516837\"\r";
const char atCommand9[] = "AT+CMGS=\"+27725138668\"\r";
const char atCommandA[] = "AT+CMGD=1,4\r";

const char atResponse1[] = "\r\nOK\r\n";
const char atResponse2[] = "ERROR";
const char atResponse3[] = "+CMTI: \"SM\",";
const char atResponse4[] = "> ";
const char atResponse5[] = "RING";
const char atResponse6[] = "NO CARRIER";
const char atResponse7[] = "NO ANSWER";
const char atResponse8[] = "+CFUN: 1";
const char atResponse9[] = "+CPIN: READY";



const char secretCode[]  = "20!4";
const char secretCode0[] = "20!4#l1";  //to turn lights ON
const char secretCode1[] = "20!4#l0";  //to turn lights OFF
const char secretCode2[] = "20!4#ls";  //to get STATUS of lights
const char secretCode3[] = "20!4#gt";  //to get temperature reading
const char secretCode4[] = "20!4#da";  //to de-activate the alarm
const char secretCode5[] = "20!4#aa";  //to activate the alarm
const char secretCode6[] = "20!4#as";  //to get the STATUS of the alarm
const char secretCode7[] = "20!4#cg";  //to close the electric gate
const char secretCode8[] = "20!4#og";  //to open the electric gate
const char secretCode9[] = "20!4#gs";  //to get the STATUS of the electric gate to see if its OPEN/CLOSED
const char secretCodeA[] = "20!4#ps";  //to get the STATUS of the power supply if its interrupted or not
const char secretCodeB[] = "20!4#rt";  //to get set temperature thtreshold value
const char secretCodeC[] = "20!4#d";   //to set Light On / OFF Delay
const char secretCodeD[] = "20!4#t";   //to set Light On / OFF Delay

const char sms1[] = "Light is ON";
const char sms2[] = "Light is OFF";
const char sms3[] = "Gate is open";
const char sms4[] = "Gate is closed";
const char sms5[] = "Alarm is ON";
const char sms6[] = "Alarm is OFF";
const char sms7[] = "Temperature is high";
const char sms8[] = "Power supply is OK";
const char sms9[] = "Power supply is not OK";
const char smsA[] = "Temperature Threshold is set to ";
const char smsB[] = " degree C";
const char smsC[] = "Temperature is ";
const char smsD[] = "Cannot control Gate. Voltage is not Ok";
const char smsE[] = "Incorrect Code Received";
const char smsF[] = "Light Will Turn ON after ";
const char smsG[] = "Light will turn OFF after ";
const char smsH[] = " minutes";
const char smsI[] = "First time use. ";
const char smsJ[] = " Threshold is not set.";

//Function Prototypes
char *CopyConst2Ram(char *dest, const char *src);

void DelayXSec(unsigned long int sec);

char *CopyConst2Ram(char *dest, const char *src);
void GSM_RESET();
void Extract_SMS(char *s1, char *s2);
void Get_SMS_gsmBufferIndex(char *s1, char *s2);
void Get_GSM_Time(char *s1, char *s2);
void Get_Code(char *s1, char *s2);
void GSM_Send_Const_Command(char *s1, char *s2, const char *s3, const char *s4, unsigned int *idx, char *gsmAttempt, char clr);
void GSM_Get_SMS(char *s1, char *s2, const char *s3, const char *s4, char *s5, unsigned int *idx, char *gsmAttempt, char *s6, char clr);
void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, char *s8, unsigned int *idx, char *gsmAttempt, char clr);

#define SEND_AT_COMMAND GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand1, &gsmBufferIndex, &gsmAttempt, 1);
#define SET_GSM_BAUDRATE  GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand4, &gsmBufferIndex, &gsmAttempt, 1);
#define SET_GSM_TEXT_MODE GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand5, &gsmBufferIndex, &gsmAttempt, 1);
#define SET_SIM_MEMORY_FOR_SMS GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand6, &gsmBufferIndex, &gsmAttempt, 1);
#define ENABLE_NEW_SMS_NOTIFICATION GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand7, &gsmBufferIndex, &gsmAttempt, 1);
#define DELETE_ALL_SMS GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommandA, &gsmBufferIndex, &gsmAttempt, 1);
#define READ_SMS GSM_Get_SMS(gsmBuffer, buffer1, atResponse1, atCommand8, smsIndex, &gsmBufferIndex, &gsmAttempt, sms, 1);
#define SEND_SMS Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
Some day I wish to write like this...for now I get dizzy.o_O
 

jayanthd

Joined Jul 4, 2015
945
This is how Send_SMS works.

Code:
Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
atResponse1 and atResponse4 for responses and

atCommand1, atCommand5, atCommand9 for AT commands

C:
//GSM Constant Strings
const char atCommand1[] = "AT\r";
const char atCommand2[] = "ATE0\r";
const char atCommand3[] = "ATE1\r";
const char atCommand4[] = "AT+IPR=9600\r";
const char atCommand5[] = "AT+CMGF=1\r";
const char atCommand6[] = "AT+CPMS=\"SM\",\"SM\",\"SM\"\r";
const char atCommand7[] = "AT+CNMI=2,1\r";
const char atCommand8[] = "AT+CMGR=";
//const char atCommand9[] = "AT+CMGS=\"9900516837\"\r";
const char atCommand9[] = "AT+CMGS=\"+27725138668\"\r";
const char atCommandA[] = "AT+CMGD=1,4\r";

const char atResponse1[] = "\r\nOK\r\n";
const char atResponse2[] = "ERROR";
const char atResponse3[] = "+CMTI: \"SM\",";
const char atResponse4[] = "> ";
const char atResponse5[] = "RING";
const char atResponse6[] = "NO CARRIER";
const char atResponse7[] = "NO ANSWER";
const char atResponse8[] = "+CFUN: 1";
const char atResponse9[] = "+CPIN: READY";
Inside the function the code is

C:
void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, char *s8, unsigned int *idx, char *gsmAttempt, char clr) {
    asm clrwdt

    while(strstr(s1, CopyConst2Ram(s2, s3)) == 0) {
        asm clrwdt
        GSM_Send_Const_Command(s1, s2, s3, s5, idx, gsmAttempt, 1);
        GSM_Send_Const_Command(s1, s2, s3, s6, idx, gsmAttempt, 1);
        GSM_Send_Const_Command(s1, s2, s4, s7, idx, gsmAttempt, 1);

        UART1_Write_Text(s8);
        Delay_ms(500);
        UART1_Write(0x1A);

        DelayXSec(6);
    }

    memset(gsmBuffer, '\0', sizeof(gsmBuffer));
    (*idx) = 0;
    asm clrwdt
}

s1 is a pointer to gsmBuffer and common to all functions
s2 is pointer to buffer1 which is also common to all functions and it is used in CopyConst2Ram() function as ram buffer to copy rom strings that is at responses to ram.

There are three function calls inside Send_SMS()

C:
GSM_Send_Const_Command(s1, s2, s3, s5, idx, gsmAttempt, 1);
GSM_Send_Const_Command(s1, s2, s3, s6, idx, gsmAttempt, 1);
GSM_Send_Const_Command(s1, s2, s4, s7, idx, gsmAttempt, 1);
The third parameter used is S3 and S4 and they are pointers to atResponse1 and atResponse4.

4th parameters used are s5, s6, s7 and these are pointers to atCommand1, atCommand5, atCommand9

1st GSM_Send_Const_Command() sends AT\r and checks if \r\nOK\r\n is received. If yes, then the buffers are cleared and buffer index is also cleared and function returns.

2nd GSM_Send_Const_Command() sends At+CMGF=1\r to set text mode and checks again if \r\nOK\r\n is received. If yes, then again buffer and index are cleared and function returns.

3rd GSM_Send_Const_Command() sends AT+CMGS=Your Mobile Number... and checks if > is received. If yes then below code is executed

C:
UART1_Write_Text(s8);
Delay_ms(500);
UART1_Write(0x1A);
s8 is pointer to ram buffer and it contains SMS. I used ram buffer because I also wanted to send temperature value as SMS and temperature value converted ibto string was in ram.

you can change this to


C:
void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, const char *s8, unsigned int *idx, char *gsmAttempt, char clr) {
    asm clrwdt

    while(strstr(s1, CopyConst2Ram(s2, s3)) == 0) {
        asm clrwdt
        GSM_Send_Const_Command(s1, s2, s3, s5, idx, gsmAttempt, 1);
        GSM_Send_Const_Command(s1, s2, s3, s6, idx, gsmAttempt, 1);
        GSM_Send_Const_Command(s1, s2, s4, s7, idx, gsmAttempt, 1);

        UART1_Write_Text(CopyConst2Ram(s2, s8));
        Delay_ms(500);
        UART1_Write(0x1A);

        DelayXSec(6);
    }

    memset(gsmBuffer, '\0', sizeof(gsmBuffer));
    (*idx) = 0;
    asm clrwdt
}
for sending rom strings as SMS.

finally 0x1A is sent and it waits for a while to get the \r\nOK\r\n response and if this response is received then the function returns either clearing the buffer or without clearing based on clr value.


Some day I wish to write like this...for now I get dizzy.
You can if you use

PIC18F13K22
PIC18F14K22
PIC18F25K22
PIC18F26K22
PIC18F45K22
PIC18F46K22
PIC18F66K22
PIC18F87K22
 

jayanthd

Joined Jul 4, 2015
945
Do you also want to read SMS ?


Reading SMS

C:
void GSM_Get_SMS(char *s1, char *s2, const char *s3, const char *s4, char *s5, unsigned int *idx, char *gsmAttempt, char *s6, char clr) {
    CLEAR_WATCH_DOG_TIMER
    while(strstr(s1, CopyConst2Ram(s2, s3)) == 0) {
        CopyConst2Ram(s2, s4);
        CLEAR_WATCH_DOG_TIMER
        strcat(s2, s5);
        strcat(s2, "\r");
        UART1_Write_Text(s2);
        CLEAR_WATCH_DOG_TIMER
        DelayXSec(2);
        CLEAR_WATCH_DOG_TIMER
        if((*gsmAttempt)++ == 3) {
            GSM_RESET() ;
            CLEAR_WATCH_DOG_TIMER
            (*gsmAttempt) = 0;
            (*idx) = 0;
            memset(gsmBuffer, '\0', sizeof(gsmBuffer));
        }
    }

    (*idx) = 0;

    Extract_SMS(s1, s6);
    CLEAR_WATCH_DOG_TIMER

    if(clr)memset(gsmBuffer, '\0', sizeof(gsmBuffer));
    CLEAR_WATCH_DOG_TIMER
}

C:
GSM_Get_SMS(gsmBuffer, buffer1, atResponse1, atCommand8, smsIndex, &gsmBufferIndex, &gsmAttempt, sms, 1);

C:
//GSM Constant Strings
const char atCommand1[] = "AT\r";
const char atCommand2[] = "ATE0\r";
const char atCommand3[] = "ATE1\r";
const char atCommand4[] = "AT+IPR=9600\r";
const char atCommand5[] = "AT+CMGF=1\r";
const char atCommand6[] = "AT+CPMS=\"SM\",\"SM\",\"SM\"\r";
const char atCommand7[] = "AT+CNMI=2,1\r";
const char atCommand8[] = "AT+CMGR=";
const char atCommand9[] = "AT+CMGS=\"+27000038668\"\r";
const char atCommandA[] = "AT+CMGD=1,4\r";

const char atResponse1[] = "\r\nOK\r\n";
const char atResponse2[] = "ERROR";
const char atResponse3[] = "+CMTI: \"SM\",";
const char atResponse4[] = "> ";
const char atResponse5[] = "RING";
const char atResponse6[] = "NO CARRIER";
const char atResponse7[] = "NO ANSWER";
const char atResponse8[] = "+CFUN: 1";
const char atResponse9[] = "+CPIN: READY";

C:
char gsmBuffer[270];
char message[50];
char buffer1[50];
char buffer2[50];
char sms[100];
char smsIndex[4];
char value[4];
char str[23];
char gsmAttempt = 0;

In the below call

[
C:
GSM_Get_SMS(gsmBuffer, buffer1, atResponse1, atCommand8, smsIndex, &gsmBufferIndex, &gsmAttempt, sms, 1);
gsmBuffer and buffer1 are used asusual.

again atResponse1 = \r\nOK\r\n
and
atCommand8 = "AT+CMGR="

In my code I had enabled new SMS notification by issuing "AT+CNMI=2,1\r"; once during GSM Initialization before entering while(1) and when new SMS notification was received, I was extracting the SMS index and then use the index with the above function call to read the SMS at that index and then Extract the actual SMS eliminating the AT+CMGR response header.

If you want to read SMS at index 0 always then I can modify the code for you. For that you have to make sure that when SMS is received you read it and delete it to keep the 0 index free for next SMS.
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
I do have a few questions but later, for now I got a problem with the modem.
I was checking the responses I get when I try to send SMS through Realterm.
And it did SMS with a "+CME: 13" ERROR. which is SIM error and gets stuck after this modem responses with error to "AT" also. At first it was working. I was sending SMS one after the other

I am checking the modem, so it might take a while to get back. I do not have any other modem to experiment. I got this one with great difficulty. If I buy one it will take a month to get to me. They are not available locally.
 

jayanthd

Joined Jul 4, 2015
945
Whether you use ATE0 or ATE1 it will work with my code. You only have to use proper response strings from the rom strings for checking.

If you use ATE0 then check for "\r\n>" response. If it is received then send the actual SMS message and then check for \r\nOK\r\n and if this is received then you can print SMS sent on LCD
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
I like to know how to send like below
"You have Message.
Blah !Blah !Blah !"

First line is header and below is the msg.
I like to send just one SMS like that, not two.

Would ATE1 use more space as it would checks response with lot of characters ?
 

jayanthd

Joined Jul 4, 2015
945
Try

"You have Message.\r\nBlah !Blah !Blah !\r\n"

or

Try

"You have Message.\rBlah !Blah !Blah !\r\n"


ATE1 just makes the modem echo what you have sent with additional OK or error or other response data. If you don't want echoing then send ATE0 once.


ATE1 will cause lengthier response and so it takes more ram.
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
Wouldn't an echo response require more memory to check the response rather than an none echo responses ?
 
Top