CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Receiving TXT messages - SUPERSEDED / OLD
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Jul 10, 2012 2:33 pm     Reply with quote

Quote:
Must i only send 1 command at a time ?
!Led1 1


Exactly.

NO multiple commands.


... what is pin D1 doing? do you see activity?
_________________
CCS PCM 5.078 & CCS PCH 5.093
dasilvarsa



Joined: 17 May 2007
Posts: 5

View user's profile Send private message

PostPosted: Tue Jul 10, 2012 2:43 pm     Reply with quote

OK It's working NOW
My module only outputs uppercase even if I send lower case SMS
Strange but true. I think it's a setting on the module.
I changed this line

const char CMD1[8][7]={"LED1 0","LED1 1","LED2 0","LED2 1","LED3 0","LED3 1","LED4 0","LED4 1"};

Thanks for the code,
If you have any other snippets please post. Lots of people working on GSM
nowdays.
Regards
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Jul 10, 2012 3:23 pm     Reply with quote

Hey! Thats great news!
I'm really happy my code helped you!

Quote:
Thanks for the code,
If you have any other snippets please post. Lots of people working on GSM
nowdays.


Right back at you!
should you modify or improve upon my code, please post it on this thread...




Gabriel
_________________
CCS PCM 5.078 & CCS PCH 5.093
ArthurWong



Joined: 28 Jan 2013
Posts: 11

View user's profile Send private message MSN Messenger

PostPosted: Mon Jan 28, 2013 2:28 am     Reply with quote

Gabriel wrote:
Yeah... thats true... i dont know how i missed that...
WTF?

GET_CMD() should be int instead of void...


Thanks for picking that up...

G.


Hi Gabriel
may i know what is the problem of it?
i also got the same problem
what i need to change for my coding?
ArthurWong



Joined: 28 Jan 2013
Posts: 11

View user's profile Send private message MSN Messenger

PostPosted: Mon Jan 28, 2013 2:38 am     Reply with quote

ArthurWong wrote:
Gabriel wrote:
Yeah... thats true... i dont know how i missed that...
WTF?

GET_CMD() should be int instead of void...


Thanks for picking that up...

G.


Hi Gabriel
may i know what is the problem of it?
i also got the same problem
what i need to change for my coding?




this problem solve but got another problem

Function used but not defined....DO_CMD SCR=871


Code:
 if (GET_CMD())
               {
                  if(DEL_SMS())
                  {
                     DO_CMD() ;
                  }
               }
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Jan 28, 2013 7:19 am     Reply with quote

Hi Arthur,

EDIT: l just checked the code again... DO CMD was declared as a INT and definde as VOID... ive Changed the define to VOID now..
that should solve your problem.... sorry.



Nevermind:

Code:
*/
The posted code should compile without any problems.
have you done any modifications to the code?
i assume you are trying to build on this code to control somthing other than LEDs...

DO_CMD() is defined (at least on the posted code) so your error must be something else....
*/



In a few weeks im going to be posting an updated GSM/SMS code... A Generic GSM/SMS "Driver" if you will...you could wait for that if this is not urgent..

I'd recommend you only use the code posted on this thread as a learning exercise to get a general idea on how to do this kind of thing...

Post your code so that i may help you better..


G
_________________
CCS PCM 5.078 & CCS PCH 5.093
ArthurWong



Joined: 28 Jan 2013
Posts: 11

View user's profile Send private message MSN Messenger

PostPosted: Mon Jan 28, 2013 8:38 am     Reply with quote

Gabriel wrote:
Hi Arthur,

EDIT: l just checked the code again... DO CMD was declared as a INT and definde as VOID... ive Changed the define to VOID now..
that should solve your problem.... sorry.



Nevermind:

Code:
*/
The posted code should compile without any problems.
have you done any modifications to the code?
i assume you are trying to build on this code to control somthing other than LEDs...

DO_CMD() is defined (at least on the posted code) so your error must be something else....
*/



In a few weeks im going to be posting an updated GSM/SMS code... A Generic GSM/SMS "Driver" if you will...you could wait for that if this is not urgent..

I'd recommend you only use the code posted on this thread as a learning exercise to get a general idea on how to do this kind of thing...

Post your code so that i may help you better..


G


actually i just want to try to on my C4 pin when receive message, but even i change your code and try to send the message, nothing change...i change all D1 into C4 for my LED output...i am using PIC16F876A with wavecom fastrack(M1206B)...software PIC C compiler...i dont have problem with sending sms, but got problem with receive sms..for storage i want to use sim storage..hope can get some advice from you and others too

Code:
#include <16f876a.h>
#include <string.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT
#use delay(clock=20000000) //must be 20 MHz

#use rs232 (baud=9600, bits=8, xmit=pin_c6, rcv=pin_c7, parity=n, stream=GSM)



void SerialInt();          // USART INT handler
int TEST_AT();            // Test Modem
int SET_MEM();            // Set used memory
int SET_PDU();            // Set PDU mode
int SET_CNMI();           // basically, set to receive alerts of new sms
int SMSALERT();           // waits for the sms alert.
int READ_SMS();           // cleans text message
void DO_CMD();             // does commands
int DEL_SMS();            // deletes SMS
int GET_CMD();            // gets command
int GET_OK(int Stop_Search);             // Just searches for an OK.

volatile int  counter_search=0;            //counter to traverse the array
volatile int  counter_read=0;             //counter to fill the array

Volatile int HitCounter=0;                // for string comparison
Volatile int Next_CMD=0;


volatile Char Recieve_String[70];   //buffer for incoming data

void main()
{
   SET_TRIS_A( 0x00 );     // to avoid floating pins
   SET_TRIS_B( 0x00 );
   OUTPUT_B(0X00);
   SET_TRIS_C( 0x80 );


   enable_interrupts(INT_RDA);  // enable RDA interrupts
   enable_interrupts(GLOBAL);   // enable global ints


 output_high(PIN_C4);           // blink for circuit 'ON' confirmation
 delay_ms(500);
 output_low(PIN_C4);
 delay_ms(500);
 output_high(PIN_C4);
 delay_ms(500);
 output_low(PIN_C4);
 Delay_ms(1000);

while(1)
{

 if(TEST_AT())
 {
    if(SET_MEM())
    {
      if(SET_PDU())
      {
        if(SET_CNMI())
        {
          if(SMSALERT())
          {
            if(READ_SMS())
            {
               if(GET_CMD())
               {
                  if(DEL_SMS())
                  {
                     DO_CMD();
                  }
               }
               else
               DEL_SMS();
            }
          }
        }
      }
    }
  }

}

}


int TEST_AT()
{
         counter_read=0;

         printf("AT");                //send command
         putchar(0x0D);                //send return ('enter' in hyperterminal)

         output_high(PIN_C4);
         While(counter_read<=8)             //"A T \R \R \N O K \R \N" characters returned by modem
         {
         }
         output_low(PIN_C4);

         counter_read=0;
         Delay_ms(500);               // ignore all remaining characters received

         if(GET_OK(0X0A))
            Return(1);
         else return(0);

}

int SET_MEM()
{
      counter_read=0;              //reset all counters.

      printf("AT+CPMS=\"ME\",\"ME\",\"ME\"");             //text part of the command.
      putchar(0x0D);                  // enter


         While(counter_read<25)      // stay here, ignore first 25 chars
         {
         }

         counter_read=0;              // start filling up the array from cero...from here on, keep the incoming text for parsing

         while(counter_read<=28)      // acquire all pertinent text, I'm only looking for an "OK" but for now I'm keeping all incoming txt.
         {                            // maybe for future use...
         }

         counter_read=0;

         Delay_ms(500);              // ignore all remaining characters received..if any.

         if(GET_OK(0X1C))
            Return(1);
         else return(0);
}


int SET_PDU()
{
         counter_read=0;

         printf("AT+CMGF=1");                //send command
         putchar(0x0D);                //send return

         While(counter_read<=15)       // get all returned text
         {
         }

         counter_read=0;

         Delay_ms(500);               // ignore all remaining characters recieved

         if(GET_OK(0X0E))
            Return(1);
         else return(0);
}


int SET_CNMI()
{
      counter_read=0;              //reset all counters.

      printf("AT+CNMI=2,1,2,0,0");             //text part of the command.
      putchar(0x0D);                //send return

         While(counter_read<24)      // read all data
         {
         }

         counter_read=0;

         Delay_ms(500);              // ignore all remaining characters recieved..if any.

         if(GET_OK(0X17))
            Return(1);
         else return(0);
}

int SMSALERT()
{
   const char StrCMTI[]={"+CMTI"};

         counter_read=0;

         While(counter_read<=16)      // read all data
         {
            output_high(PIN_C4);          // signal ready to receive sms
         }
         counter_read=0;

         Delay_ms(500);              // ignore all remaining characters recieved..if any.
         output_low(PIN_C4);           // off receive ready light.
         counter_search=2;

         HitCounter=0;

         while((HitCounter!=5)&&(counter_search<8))
         {
            if(Recieve_String[counter_search]==StrCMTI[counter_search-2])
            HitCounter++;

            counter_search++;
         }

   if(HitCounter==0x05)
      Return(1);
         else return(0);
}


int READ_SMS()
{
   counter_read=0;

   printf("AT+CMGR=1");             // send command, MEMORY LOCATION OF SMS IS ALWAYS ONE, SINCE I DELETE THEM AFTER PROSCESING
   putchar(0x0D);

   delay_ms(3000);                  // long [spam] message... so give time,  buffer will loop back one time...
                                    // text will be on second fill.
   counter_read=0;

   if(GET_OK(0X45))
      Return(1);
   else return(0);

}

int GET_CMD()
{
   const char CMD1[8][7]={"Led1 0","Led1 1","Led2 0","Led2 1","Led3 0","Led3 1","Led4 0","Led4 1"};

   int offset=0;
   int store_counter=0;
   counter_search=0;


   while((Recieve_String[counter_search]!='!')&&(counter_search<69)) // wait till command indicator is found '!'
   {
      counter_search++;
   }

   counter_search=counter_search+1;             // increment one to actual first letter of command
   store_Counter=counter_search;                // store current position for multiple searches
   NEXT_CMD=0;                                  // NEXT_CMD keeps track of the command being read, thus used

   while((HitCounter!=6)&&(NEXT_CMD<8))                     // compare to all commands in list.
   {
      counter_search=store_Counter;                // initialize counter search with stored counter value.
      offset=0;                                    // since value of counter is unknown use a separate counter for the const array
      HitCounter=0;                                // counts number of equal letters found.

      while((HitCounter!=6)&&(offset<=6))          // keeps the counters in check...to not overshoot. and compares the strings
      {
         if(Recieve_String[counter_search]==CMD1[NEXT_CMD][offset])  // if letter is found
            HitCounter++;
            offset++;
            counter_search++;
      }

      if(HitCounter==6)          // if 6 chars found...exit..
      {
         Return(1);
      }

      NEXT_CMD++;                // if increase to search next command.

   }

   Return(0);
}


Void DO_CMD()
{
   if(NEXT_CMD==0)output_low(PIN_B1);
   if(NEXT_CMD==1)output_high(PIN_B1);

   if(NEXT_CMD==2)output_low(PIN_B2);
   if(NEXT_CMD==3)output_high(PIN_B2);

   if(NEXT_CMD==4)output_low(PIN_B3);
   if(NEXT_CMD==5)output_high(PIN_B3);

   if(NEXT_CMD==6)output_low(PIN_C4);
   if(NEXT_CMD==7)output_high(PIN_C4);

}

int DEL_SMS()
{
         counter_read=0;

         printf("AT+CMGD=1");                //send command
         putchar(0x0D);                //send return

         While(counter_read<=15)       // get all returned text
         {
         }

         counter_read=0;

         Delay_ms(500);               // ignore all remaining characters received

         if(GET_OK(0X0E))
            Return(1);
         else return(0);
}


int GET_OK(Stop_Search)
{
         counter_search=0;

         while((Recieve_String[counter_search]!='O')&&(counter_search<Stop_Search))   //check buffer until an 'O' is found or 10 chars have been checked.
         {
            counter_search++;     //obvious
         }

         if((Recieve_String[counter_search]=='O')&&(Recieve_String[counter_search+1]=='K'))  //check for a 'K' after the 'O'
         {
            counter_search=0;
            Return(1);              //function returns true
         }
         Return(0);
         counter_search=0;
}



#INT_RDA
void SerialInt()
{
   Recieve_String[counter_read]=getchar();
   counter_read++;
   if(counter_read==69)counter_read=0;
}
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Jan 28, 2013 9:13 am     Reply with quote

A couple of things...

I know i put it there... but remove the TRIS settings... let the compiler do that ...

you are using C4 as your "status" pin, as well as the pin you are actually trying to control...

C4 blinks at the begining of the code, when TEST_AT runs, When the SMSALERT runs... and then when you send the module the !Led4 command...

i suggest changing the status LED to a diferent LED... to avoid confusion..

also something VERY important:
this code only checks the SMS's located in adress ONE(1).... and deletes the SMS's on the same address...

before testing the code, DELETE ALL SMS's in the module... so when the code is runing and you send an SMS the module will place it on memory location one....


for memory locations:

Look at the function SET_MEM()...
Code:
 printf("AT+CPMS=\"ME\",\"ME\",\"ME\"");


read the specific options for your module... i believe for sim card memory you should use "SM" instead of "ME"..

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
ArthurWong



Joined: 28 Jan 2013
Posts: 11

View user's profile Send private message MSN Messenger

PostPosted: Mon Jan 28, 2013 9:39 am     Reply with quote

I already delete all my sim message and remove the trisc and also change ME to SM.....but it look like no response (See no light and only blinking starting), even my GSM also no response (slow blink) and i also cant receive any notification....is it problem with my GSM or i should change it to TC35 GSM ?

When i change my sim to phone, i receive a lot of previous message that i sent. Is that also mean the coding cant read the SMS by using this GSM wavecom fastrack? really headache now....i just want to test receive SMS to activate the LED.

When i test with the hyper terminal it just show ( AT ) only...as i know it is because it not yet receive message so it can't move further.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Jan 28, 2013 12:47 pm     Reply with quote

If you test the PIC code on HyperTerminal,

You should see AT only... if you type back to the PIC "OK" and 7 (any)more characters, it will reply with the next line...

Your modem should have "local echo on"... ATE1

You need to ensure your comms PIC>CELL are 100% good...

Disable flow control...

Also if your cell module has no connection to the network, that's a different story which no amount of pic code can fix.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
ArthurWong



Joined: 28 Jan 2013
Posts: 11

View user's profile Send private message MSN Messenger

PostPosted: Mon Jan 28, 2013 9:45 pm     Reply with quote

Gabriel wrote:
if you test the PIC code on Hiperterminal,

you should see AT only... if you type back to the PIC "OK" and 7 (any)more characters, it will reply with the next line...

..your modem should have "local echo on"... ATE1

you need to ensure your coms PIC>CELL are 100% good...

disable flow control...

also if your cell module has no conection to the network, thats a diferent story which no amount of pic code han fix..

G.


that mean i should put ATE1 in my program ? and i also need to disable the flow control (become none)(AT+IFC=0,0)?
ArthurWong



Joined: 28 Jan 2013
Posts: 11

View user's profile Send private message MSN Messenger

PostPosted: Tue Jan 29, 2013 2:38 am     Reply with quote

ArthurWong wrote:
Gabriel wrote:
if you test the PIC code on Hiperterminal,

you should see AT only... if you type back to the PIC "OK" and 7 (any)more characters, it will reply with the next line...

..your modem should have "local echo on"... ATE1

you need to ensure your coms PIC>CELL are 100% good...

disable flow control...

also if your cell module has no conection to the network, thats a diferent story which no amount of pic code han fix..

G.


that mean i should put ATE1 in my program ? and i also need to disable the flow control (become none)(AT+IFC=0,0)?


Hi Gabriel i put ATE1 command like code below and i get always low output or LCD display just show "return"...it is ok with hyper teminal (if i put >8 character i will go back "initialize") but when i plug into GSM and test it just show "return" and not looping back....can get some advice fron you ?

If using tc35 GSM it will loop between "intialize" then go to "Return" repeating no end even though i send the sms to GSM.
Code:

int TEST_AT()
{
counter_read=0;

printf("AT\r\n");   //send command
delay_ms(500);
printf("ATE1\r\n");               
delay_ms(500);
           
output_high(PIN_C4);
lcd_gotoxy(1,1);
lcd_putc("Initialize....");
delay_ms(1000);
While(counter_read<=8)    //"A T \R \R \N O K \R \N" characters returned by modem
  {
  }

output_low(PIN_C4);
lcd_gotoxy(1,1);
lcd_putc("Return");
delay_ms(1000);
counter_read=0;
delay_ms(500);   // ignore all remaining characters received

if(GET_OK(0X0A))
   Return(1);
else return(0);
}
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Jan 29, 2013 7:43 am     Reply with quote

1) _without_connection to the PIC (in hyperterminal), enable local echo, and disable flow control... save settings.

2) Send AT\r to the module, it should reply (including local echo): //"A T \R \R \N O K \R \N"

got that working? good... now...


3) connect the pic to hypertermninal using _the original posted code_..
you should see the pic send "AT"... and wait for a reply..

4) the you (reply) type into hyperterminal: //"A T \R \R \N O K \R \N"
for testing you can just type: ATXXXOKXX.. (8+characters)

the pic should then reply with the next command SET_MEM()...


do not modify the original code until you get it working...

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
ArthurWong



Joined: 28 Jan 2013
Posts: 11

View user's profile Send private message MSN Messenger

PostPosted: Tue Jan 29, 2013 10:26 am     Reply with quote

Gabriel wrote:
1) _without_connection to the PIC (in hyperterminal), enable local echo, and disable flow control... save settings.

2) Send AT\r to the module, it should reply (including local echo): //"A T \R \R \N O K \R \N"

got that working? good... now...


3) connect the pic to hypertermninal using _the original posted code_..
you should see the pic send "AT"... and wait for a reply..

4) the you (reply) type into hyperterminal: //"A T \R \R \N O K \R \N"
for testing you can just type: ATXXXOKXX.. (8+characters)

the pic should then reply with the next command SET_MEM()...


do not modify the original code until you get it working...

G.


yup, that is work Gabriel in the hyperteminal that show "AT" then if i type more than 8 char it show the next command..


what can i do in the next step? i am using 16f876A ...i got LCD and i am using it...and on the same time how can i test my GSM with hyperteminal that state it got receive sms? in my board i just have pin_C4 as my LED output that why i send "!LED4 1" to turn on LED...the others i try use LCD display....just hope can command using the sms
ArthurWong



Joined: 28 Jan 2013
Posts: 11

View user's profile Send private message MSN Messenger

Work Half
PostPosted: Wed Jan 30, 2013 12:54 am     Reply with quote

Hi Gabriel, finally i manage to work until code below only...

I just can work until output_low(PIN_D1)(int SMSALERT()), but the problem is when i send "!LED4 1", the command look like can't read it and the output part "output_high(PIN_B4)(Void DO_CMD())" can't trigger after receive my message...

Just "output_low(PIN_D1)" then go back to starting again(int TEST_AT() )...

Code:
int SMSALERT()
{
   const char StrCMTI[]={"+CMTI"};

         counter_read=0;

         While(counter_read<=16)      // read all data
         {
            output_high(PIN_D1);          // signal ready to receive sms
         }
         counter_read=0;

         Delay_ms(500);              // ignore all remaining characters recieved..if any.
         output_low(PIN_D1);           // off receive ready light.
         counter_search=2;

         HitCounter=0;

         while((HitCounter!=5)&&(counter_search<8))
         {
            if(Recieve_String[counter_search]==StrCMTI[counter_search-2])
            HitCounter++;

            counter_search++;
         }
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group