|
|
View previous topic :: View next topic |
Author |
Message |
bhyatyab
Joined: 26 Jan 2005 Posts: 13
|
Sending AT Commands via RS232 |
Posted: Mon Feb 07, 2005 4:10 am |
|
|
Hi
Im am trying to send AT Commands via RS232 to a cell phone. The code below does not seem to work. Can anyone please help me.
Thanks
#include <18F452.h>
#device ICD=TRUE
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, BROWNOUT, BORV20, PUT, STVREN, DEBUG, LVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7)
void main(void){
/* **************************************************************/
/* INITIALISATION SECTION
/*
/* Part of Bootup Sequence. All peripherals
/* are configured and activated.
/*
/* ************************************************************* */
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_16);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_timer_2(T2_DIV_BY_16,99,16);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(GLOBAL);
{
printf("AT");
printf("0x0d");
printf("AT&K3");
printf("0x0d");
printf("AT+CSQ");
printf("0x0d");
printf("AT+CMGF=1");
printf("0x0d");
puts( "AT+CSCA=\"+27831234567\"");
printf("0x0d");
puts( "AT+CMGS=\"+27841234569\"");
printf("0x0d");
printf("Test");
printf("0x5a");
printf("0x5e");
}
} |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Feb 07, 2005 4:30 am |
|
|
Do you see the expected texts when connecting the PIC to a PC instead of to the phone?
You are not checking the responses sent by the phone. This might be ok for a quick and dirty hack, but at least at a small delay in between sending the commands.
I haven't checked the commands, but it looks to me like you don't need them all. |
|
|
Guest
|
Re: Sending AT Commands via RS232 |
Posted: Mon Feb 07, 2005 3:58 pm |
|
|
bhyatyab wrote: | Hi
Im am trying to send AT Commands via RS232 to a cell phone. The code below does not seem to work. Can anyone please help me.
Thanks
#include <18F452.h>
#device ICD=TRUE
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, BROWNOUT, BORV20, PUT, STVREN, DEBUG, LVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7)
void main(void){
/* **************************************************************/
/* INITIALISATION SECTION
/*
/* Part of Bootup Sequence. All peripherals
/* are configured and activated.
/*
/* ************************************************************* */
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_16);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_timer_2(T2_DIV_BY_16,99,16);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(GLOBAL);
{
printf("AT");
printf("0x0d");
printf("AT&K3");
printf("0x0d");
printf("AT+CSQ");
printf("0x0d");
printf("AT+CMGF=1");
printf("0x0d");
puts( "AT+CSCA=\"+27831234567\"");
printf("0x0d");
puts( "AT+CMGS=\"+27841234569\"");
printf("0x0d");
printf("Test");
printf("0x5a");
printf("0x5e");
}
} |
Either put a delay between commands or wait for a reply.
Also your code
printf("AT");
printf("0x0d");
Try this:
printf("AT\r"); // add the 0X0D in one printf()
delay_ms(3); // 3 milliseonds for OK repay.
next command |
|
|
LouiseG
Joined: 03 Nov 2004 Posts: 17 Location: London...UK!
|
|
Posted: Mon Feb 07, 2005 4:04 pm |
|
|
Here is a bit if code that i was sending a text message to a radio unit once:
Code: |
#define button PIN_A4
char c;
#define CR 0x0d //carriage return
#define LF 0x0a //line feed
#define CZ 0X1a //ctrl Z
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
lcd_init();
// when i press the button, sends text message
do
{
if(input(button)==0)
{
printf("AT+CMGS=300154,1,0,152\r");
delay_ms(1000);
printf("82 0C 01 01 4F 54 53 55 20 41 6C 61 72 6D 20 54 65 73 74");
putc(CZ);
//flashes an LED jus to show gone through the above code!
output_high(PIN_B0);
delay_ms(5000);
output_low(PIN_B0);
}
}while(TRUE);
}
|
|
|
|
Kada
Joined: 22 Nov 2004 Posts: 4
|
AT Commands |
Posted: Mon Feb 07, 2005 4:18 pm |
|
|
I have tried this code and it works.
...
...
sendsms() {
byte data;
fprintf(GSM, "AT"); // AT+CMGS="<TLF NR>"<CR><NL>
fputc(CR,GSM);
if (kbhit(GSM)) {
data= fgetc(GSM);
fputc(data,PC);
} // IF
delay_ms(5000);
fprintf(PC,"%s","\r\nSMS will send to the 27206909 \r\n");
fprintf(GSM, "AT+CMGS="); // AT+CMGS="<TLF NR>"<CR><NL>
fputc(0x22,GSM); // "
fprintf(GSM,"27206909"); // AT+CMGS="<TLF NR>"<CR><NL>
fputc(0x22,GSM); // "
fputc(CR,GSM);
fprintf(GSM,"Hello world");
delay_ms(1000);
fputc(0x1A,GSM); // Ctrl-Z
} _________________ Best Regards Kada |
|
|
densi Guest
|
Re: Sending AT Commands via RS232 |
Posted: Mon Feb 07, 2005 8:57 pm |
|
|
bhyatyab wrote: | Hi
Im am trying to send AT Commands via RS232 to a cell phone. The code below does not seem to work. Can anyone please help me.
Thanks
#include <18F452.h>
#device ICD=TRUE
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, BROWNOUT, BORV20, PUT, STVREN, DEBUG, LVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7)
void main(void){
/* **************************************************************/
/* INITIALISATION SECTION
/*
/* Part of Bootup Sequence. All peripherals
/* are configured and activated.
/*
/* ************************************************************* */
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_16);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_timer_2(T2_DIV_BY_16,99,16);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(GLOBAL);
{
printf("AT");
printf("0x0d");
printf("AT&K3");
printf("0x0d");
printf("AT+CSQ");
printf("0x0d");
printf("AT+CMGF=1");
printf("0x0d");
puts( "AT+CSCA=\"+27831234567\"");
printf("0x0d");
puts( "AT+CMGS=\"+27841234569\"");
printf("0x0d");
printf("Test");
printf("0x5a");
printf("0x5e");
}
} |
hi
try this in PDU mode....
AT+CMGS=<length of pdu frame><cr> {send this code to phone}
> {response from phone, you must wait for this character, then writte the following to phone...}
<pdu frame content><�ctrl-z�> { send this data to phone, then phone will send the message built in pdu frame}
for TEXT mode:
AT+CMGS=<da><CR>text is entered
<ctrl-Z>
example:
AT+CMGS="0507751116" ==>string to send to phone
> ==> character received from phone, you mut wait for it, or make a delay_ms(10);
hello there ==> string to send to phone
OK ===> response from phone
Bye |
|
|
|
|
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
|