|
|
View previous topic :: View next topic |
Author |
Message |
gorilla135
Joined: 14 Mar 2006 Posts: 8
|
Sending and receiving fixed sms |
Posted: Tue Mar 14, 2006 6:30 am |
|
|
I am currently working on a project which involves controlling a machine via sms. have written some code but cannot get it to work. im a bit rusty on writing C. need the pic to receive a sms read and see if it is a valid command once it is recognised sends a sms back. initally i would like if it just turned on an led for testing.
any help at all would be really appreciated |
|
|
PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
|
Posted: Thu Mar 16, 2006 3:23 am |
|
|
Are you connecting the PIC to a cellular phone?
If yes, via what? |
|
|
jasonwhw
Joined: 14 Mar 2006 Posts: 8 Location: Malaysia
|
|
Posted: Thu Mar 16, 2006 4:01 am |
|
|
hey,
I am also doing quite a similar project.Currently I am able to send sms but unable to receive sms.So if anyone out there who can help, please do help us.thanks
jasonwhw. |
|
|
qleyo
Joined: 23 Aug 2005 Posts: 22
|
|
Posted: Thu Mar 16, 2006 4:36 am |
|
|
Heh my mate who works right next to me is doing something exactly the same lol so theres 4 of us (plus me) but without the SMS. I currently have this bit of code but I don't think it will work. Well it doesn't even.
Especially my gprs_error() function. I am trying to send simple AT commands to the modem and check for OK or CONNECT, then flash LEDs depending on which response I get.
Jason you say you got text sending working? Any chance I can peek at your code :D
Edit: And can someone please clarify is PIC to MODEM null connected? This is for the #use statement meaning, for XMIT should I be specifying the RX pin from modem and RCV the TX pin or XMIT to TX and RCV to RX?
Code: |
#include <18F452.h>
#include <string.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232 (BAUD=9600,XMIT=PIN_A3,RCV=PIN_A2,ERRORS,bits=8,stream=modem)
void gprs_error()
{
char msg[20];
char response_ok[25];
char response_connect[25];
strcpy(response_ok,"\r\nOK\r\n");
strcpy(response_connect,"\r\nCONNECT\r\n");
//check if command returned an error
//program will not continue until gprs returns a string
gets(msg);
//check if error returned
delay_ms(100);
if (stricmp(msg, response_ok))
output_high(PIN_B0);
else if (stricmp(msg, response_connect))
output_high(PIN_B1);
}
void delay_sec (int n)
{
while(n!=0)
{
delay_ms(200);
delay_ms(200);
delay_ms(200);
delay_ms(200);
delay_ms(200);
n = n - 1;
}
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
/***start test sequence***/
while(TRUE)
{
delay_sec(1);
output_high(PIN_B2);
fprintf(modem,"at\r\n");
delay_ms(10);
fprintf(modem,"ate0\r");
delay_ms(10);
fprintf(modem,"at#k0\r\n");
//gprs_error();
delay_ms(10);
fprintf(modem,"atd+447745691189;\r\n");
delay_sec(5);
fprintf(modem,"ath");
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
}
}
|
|
|
|
jasonwhw
Joined: 14 Mar 2006 Posts: 8 Location: Malaysia
|
|
Posted: Thu Mar 16, 2006 4:43 am |
|
|
I'm using printf command to send simple AT command to the mobile phone to send SMS out. I'm using
Code: | void SEND_SMS1()
{
PRINTF("\n\rAT+CMGS=37\n\r");
DELAY_MS(500);
PRINTF("0011000B910621550661F80000FF17");
DELAY_MS(500);
PRINTF("D3FC9C5E6E8382637ADA1EA697C9201388F87ECB41CCF7");
DELAY_MS(500);
PUTCHAR(0x1A);
} |
|
|
|
qleyo
Joined: 23 Aug 2005 Posts: 22
|
|
Posted: Thu Mar 16, 2006 7:05 am |
|
|
I tried that too i.e. using printf, but I think my problem is from
Code: | #use rs232 (BAUD=9600,XMIT=PIN_A3,RCV=PIN_A2,ERRORS,bits=8,stream=modem) |
1. I'm not sure if the XMIT pin should be specifying the TX line from the modem or thats the pin that transmits data from the PIC (and therefore should be connected to RX on modem)
2. I'm not using the default pins C6 and C7, so I think I have to use fprintf instead.
edit: ok I just hooked my pic up to hyper terminal, i get my AT commands fine. hmm don't know whats wrong now |
|
|
jasonwhw
Joined: 14 Mar 2006 Posts: 8 Location: Malaysia
|
|
Posted: Thu Mar 16, 2006 7:08 pm |
|
|
if you are not using the default pin, it will trigger the PIC to use software UART. i suggest you try again using the default pin C6 and C7(hardware UART). |
|
|
gorilla135
Joined: 14 Mar 2006 Posts: 8
|
gsm |
Posted: Mon Apr 10, 2006 11:45 am |
|
|
Code: |
#include <16F877.h> // Defines chip
#include <stdio.h> // this gets the printf() definition
#include <string.h> // string handling library
#use delay(clock=4000000) // tells compiler clock speed
#fuses hs, noprotect, nowdt, nolvp, nobrownout // sets the fuses
#use rs232(baud=9600,xmit=PIN_C6, rcv=PIN_C7, stream=GSM, ERRORS) // sets the rs232 up
#byte PORTD = 8 // portd is located at file 8
#bit injector1 = PORTD.0 // portd1 is injector1
#bit injector2 = PORTD.1 // portd2 is injector2
#bit injector3 = PORTD.2 // portd3 is injector3
#bit injector4 = PORTD.3 // portd4 is injector4
#bit lift_pump = PORTD.4 // portd5 is lift pump
.
const int CR=0x0d;
const int CZ=0x1A;
const int LF=0x0A;
char response[8];
char reply[20];
char result[2];
int read_message;
int send_message;
int delete_message;
int receive_message;
int shutdown;
void main(void)
{
set_tris_d(0xE0);
};
void send_message()
{
fprintf(GSM,"AT\r\n");
delay_ms(500); // checks are they communicating
fgets(GSM); //gets the responce and dump it
fprintf(GSM,"AT+CMGF=1\r\n"); // sends an at command to set messages to text mode
delay_ms(500); //sends a carriage return
fgets(GSM); //gets the responce and dump it
fprintf(GSM,"AT+CMGS=\"07749960685\"\r\n"); // sents the following text to this number
delay_ms(500);
fgets(GSM); //gets the responce and dump it
fprintf(GSM,"Shutdown Procedure Complete. Contact Authorities"); // the text that will actually be sent
delay_ms(100);
fputc(CZ,GSM); // sends carriage return
gets(response,GSM); // gets the confirmation reply
while(1)
{
}
void receive_message()
{
char msg_coding1[80];
char msg_coding2[80];
signed int8 result;
fgets(GSM);
fprintf(GSM,msg_coding1);
result = stricmp(msg_coding1, msg_coding2);
if(result=0) //if stricmp return 0 ==true
read_message();
else if(result=-1) // if stricmp returns -1 == false
main();
else (result=1) // if stricmp returns 1 == false
main();
};
void read_message()
{
char text_code1[6];
char text_code2 = stop
char text_code3 = start
signed int8 result;
fprintf(GSM,"+CMTI: "SM",1"); //sends the command to read the message at location 1
delay_ms(500) //wait 500ms
fgets(GSM); //gets the first line of text message and dumps it
delay_ms(500) //wait 500ms
fgets(GSM); // gets the second line and dumps it
delay_ms(500) //wait 500ms
fgets(GSM); //gets the 3rd line which is line we want
delay_ms(500) //wait 500ms
fputs(GSM,text_code); // puts the string in file called text_code
delay_ms(500)
fgets(GSM); // gets the blank line
result1 = stricmp(text_code1, text_code2);
result2 = stricmp(text_code1, text_code3);
if(result1=0 && result2=-1||1) //if result1 is true carry out shut down
shutdown(); //procedure
else if(result1 = 1||-1 && result2 = 0) // if result2 is true carry out startup
main();
else (result=1||-1 && result2= 1||-1) // if stricmp returns 1 == false
delete_message();
fgets(GSM); //gets the carriage return and dumps it
delay_ms(500) //wait 500ms
};
//this function deletes the message in location 1
void delete_message(void)
{
fprintf(GSM="AT+CMGD=1"); //deletes the text message at location1 so next command can be dealt with
delay_ms(500)
gets(response,GSM); // gets the ok response
main
};
// this function carries out the shut down procedure
void shutdown(void)
{
injector1= 0; // switch off injector 1
delay_ms(500);
injector2= 0; // switch off injector 2
delay_ms(10000); // wait ten seconds
delay_ms(10000); // wait ten seconds
delay_ms(10000); // wait ten seconds
delay_ms(10000); // wait ten seconds
delay_ms(10000); // wait ten seconds
delay_ms(10000); // wait ten seconds (1 minute)
lift_pump=0; // turn the life pump in tank off
//once the pump has been deactivated the engine will have no fuel and so the car will come to a
//halt,
receive_message(); // calls cool down period where it waits for the
// command to turn the car back on
};
|
can anyone give any advice to what i am doing wrong |
|
|
michellelicious
Joined: 15 Apr 2007 Posts: 3
|
Sending SMS via UART |
Posted: Sun Apr 15, 2007 11:39 pm |
|
|
Sending SMS via USART
Hi im Michelle Jones an ECE student Razz Hey guyz will somebody kindly send me a copy of a source code in CCS for PIC 16F877A on how to send a simple SMS in "SMS mode" through a PIC connected to a GSM module. Hopefully it would be something that can be compiled with no problem. Thank you very much. It would just be something we would learn from example. We would not totally copy the source code and use it as once.
Much appreciation,
Michelle
¤mwah!¤ |
|
|
Andreas
Joined: 25 Oct 2004 Posts: 136
|
Sending SMS |
Posted: Sun Apr 15, 2007 11:55 pm |
|
|
Hi All,
As a simple method to find out how SMS sending is working I a taking a simple terminal programm like hyperterminal and connect the modem to it and then I am trying to get a really working set of commands with sending SMS and receiving them.
If this works its easy to convert it to the pic with sending the same strings with fprintf statements.
About serial connection, just see with a led tester or a multimeter which pin on the modem has a +- 9V signal or similar ( should be pin2 or 3) and connect this pin to the rx Pin thru a level converter to the PIV the other pin connect also thru a level converter to the other pin on the modem.
usually that works, but you should read the manual if the modem needs a hardware handshake or if you can disable the hardware handshake, for the begin its always better to run without handshake saves you a lot of hours !!
There is no "CODE" out here which works for every Unit, because there are always a bit of differences to see between the models !
Best starting point is to use a modem modul with an "easy GPRS" Operating system running.
best regards
Andreas |
|
|
|
|
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
|