View previous topic :: View next topic |
Author |
Message |
Sal
Joined: 04 Mar 2010 Posts: 27 Location: Caribbean
|
|
Posted: Thu May 27, 2010 1:37 pm |
|
|
Ok. So I reset the counter_read to zero and I setup a while loop so that if counter_read is not equal to zero it advances.
Correct ?
Code: | #INT_RDA
void SerialInt()
{
Recieve_String[counter_read]=getchar();
counter_read++;
if(counter_read==69)counter_read=0;
}
void main() {
delay_ms(500);
enable_interrupts(global);
enable_interrupts(int_rda);
puts("ATE0"); // Used to turn echo off.
delay_ms(1000);
puts("at+clip=1");
delay_ms(1000);
puts("at+cpms=mt,mt,mt");
delay_ms(1000); // wait for phone to reply
puts("at+csms=1");
delay_ms(1000); // wait for phone to reply
puts("at+cnmi=1,2,0,0,1");
delay_ms(1000); // wait for phone to reply
counter_read=0;
while(counter_read<=0){ // When char. arrives, counter_read becomes >0
}
delay_ms(1500);
output_high(pin_b6);
delay_ms(1000);
output_low(pin_b6);
delay_ms(1000);
output_high(pin_b6);
}
|
|
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Thu May 27, 2010 2:37 pm |
|
|
did you try sending an sms already... i believe as is... your code will light your LED when it gets an sms......
if it does.... then we can continue.... your code looks good so far....
ill be online for 1:30 more hours....
g _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Sal
Joined: 04 Mar 2010 Posts: 27 Location: Caribbean
|
|
Posted: Thu May 27, 2010 4:31 pm |
|
|
Yes the led comes on when I send an sms.
I'm ready for the next step. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Fri May 28, 2010 5:46 am |
|
|
progress!!!!
ok well... you can ad the line
LED1!=LED1; (this is sort of pseudo code but you get the point).
and thus your led toggles with an sms..... ANY sms.
but i assume you want more specific control.
this is where this gets complicated....
now that you can detect and incomming sms you need to process it.
with the CMNI command you have set up the alarm that will tell you when your sms is arrived...
but right now actually what triggers a respond on your system is an incoming character.... not nesesarily the CMNI response....
so when your send an sms... what does your phone reply? (what string does it send your code, the string that lights your led right now)
in mine is \r\n+CMTI \n\r .....
the response string for CMNI is short as you can see... and your buffer is
bigger than the response total length and since you reset your buffer just before you start waiting for an sms.... your response will be exactly at the begining of your buffer....the part i care actually starts in position [2] of my buffer....
instead of lighting a LED when you break out of your loop, give a small delay, and call a function.
this function will look for "+CMTI" (or what ever code your phone sends)
declare 2 new counter.... i call mine counter_search.....and hit_counter.
counter_search is for going throught the buffer, without changing the position of the next incoming character, if any.... the ISR writes to the buffer on position "counter_read"...... since you will need to start looking for the string from the beggining of the buffer, if you reset counter_read to look for the string... if at that moment a new char comes in ... you will overwrite your buffer data.... and you will never find the string your looking for.... thus a new counter...
and hit counter counts the amount of characters found...
in my code i dont use string functions such as STRSTR(); i wasnt very succesfull with them and i went for manual mode.
i do the searches manually.... like so:
Code: |
counter_search=2; //my phone sends \r\n+CMTI \n\r so i start from position 2 or "+"
HitCounter=0;
while((HitCounter!=5)&&(counter_search<8)) // 5 hits/5comparisons = string found
{
if(Recieve_String[counter_search]==StrCMTI[counter_search-2]) // SrtCMTI is a const array... it only has 5 chars...so i give the counter an offset...
HitCounter++;
counter_search++;
} |
i then check how many hits i got.... if i got 5... i return 1 else return 0...
i do this in my int SMSALERT() function.... take a look at it....
you wait for the characters to arrive in you main.... i wait inside my function....and i wait for 16 chars ... you just wait for one.... both ways work.... stay with yours....
once youve identified the incoming characters as an actual CMNI alert... you light a LED....
thats the task.... identify the incoming string... and light a led only when its identified as an actual alert....
from here... we can do AT+CMGR=1 ... and get the sms... and do somthing with it...the way to process the sms is pretty much the same way you process the CMNI alert.... but for now handeling CMNI will do...
if you want you can try using STRSTR() or whatever function is appropiate for the job...... frankly i would like you to do so, so that YOU can teach me hahahaha!
in any case..... doing the work manually is not that hard...
after today... i wont be able to frequent the forum as much as i would like to.... as i am moving from argentina to panama to start a new job... so if i am MIA for a little while dont hate hhehehe....
Gabriel.... _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Sal
Joined: 04 Mar 2010 Posts: 27 Location: Caribbean
|
|
Posted: Fri May 28, 2010 6:26 am |
|
|
Moving to Panama ? I wish you all the best and great success.
I would like to thank you so very much the help you have given me and I'll get to work ASAP.
Hope to see you back online soon...
Sal |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Fri May 28, 2010 8:08 am |
|
|
i am Panamanian, but ive been out of panama for: 4 years of college in the US, and then 4 more working in argentina... now finally i get to move back to my own country.... ill be working in the construction of the new panama canal!
ill be online for the rest of the day... thats 8 more hours...
i should be back online next week...
mabey youll get to post some code today? did you have any questions on the last post i made you? _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
ederelk
Joined: 10 Mar 2011 Posts: 3
|
|
Posted: Fri Mar 11, 2011 8:11 am |
|
|
Hello Gabriel, I have been working on this project for months now and I
didn't get any result. I have a development board with pic16F877A and a wavecon gsm module Q24. I'm trying to read text msg using my pic. So far i have been able to send sms and make call using the pic and the gsm module interface (RS232). But whenever I try to read a text message from the module using the pic,and display it on the lcd it displays garbage or sometimes I feel like it does not read anything from the gsm. I'm really desperate now. I really need your help please help me.
Here is my code
Code: |
/*THIS HAS BEEN EDITED TO SUITE WAVECOM*/
#include <16F877A.h>
#include <string.h>
#include "lcd.c"
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream=gsm,ERRORS)
Char Recieve_String[70];
Int counter_read;
#INT_RDA
void SerialInt()
{
Recieve_String[counter_read]=fgetc(gsm);
counter_read++;
if(counter_read==34)
counter_read=0;
}
void main() {
delay_ms(500);
enable_interrupts(global);
enable_interrupts(int_rda);
output_low(pin_b1);
output_low(pin_b0);
output_high(pin_b6);
lcd_Init();
delay_ms(500);
printf(lcd_putc,"\fSTART ");
puts("ATE0"); // Used to turn echo off.
putc(13);
delay_ms(1000);
puts("atd 0267094444;");
putc(13);
delay_ms(10000);
//puts("at+clip=1"); //IDENTIFY CALL I DONT NEED THIS
//delay_ms(1000);
puts("at+cpms=ME,ME,ME");//use flash to store msg not sim
putc(13);
delay_ms(1000); // wait for phone to reply
//puts("at+csms=1");//SELECT SMS SERVICE I DONT NEED THIS
//delay_ms(1000); // wait for phone to reply
puts("at+cnmi=1,2,0,0,1"); // FORWARD MSG NOTIFICATION TO TE
putc(13);
delay_ms(1000); // wait for phone to reply
counter_read=0;
printf(lcd_putc,"\fCALL NOW ");
while(counter_read<=0){ // When char. arrives, counter_read becomes >0
}
delay_ms(1500);
output_high(pin_b0);
delay_ms(1000);
output_low(pin_b0);
delay_ms(1000);
output_high(pin_b0);
for(counter_read=0;counter_read<34;counter_read++){
printf(lcd_putc,"\f%c",Recieve_String[counter_read]);
delay_ms(1000);}
} |
|
|
|
dsolorzano
Joined: 29 Mar 2011 Posts: 3
|
Connecting the phone |
Posted: Tue Mar 29, 2011 5:06 am |
|
|
Sorry, I am new on this topic, how do you connect your cellphone to the pic? Thanks |
|
|
|