Need help on sending SMS from p18f4520

Status
Not open for further replies.

flyingCOW

New Member
Hi, I'm now trying to send SMS from p18f4520 to my phone. But I can't seem to send or receive the SMS.

I'm using BluOcean Serial GSM / GPRS Modem, attached is the connection from p18f4520 to the modem

and my code:

 
Last edited:
Are you sure that the ROM pointers should be far and not near. There is no need for far pointers on that chip so I suspect the library may be expecting near pointers.

Have you tried sending to a PC first?

Mike.
 
Are you sure that the ROM pointers should be far and not near. There is no need for far pointers on that chip so I suspect the library may be expecting near pointers.

Have you tried sending to a PC first?

Mike.

What do you mean by far and near pointers?
 
A far pointer is a 24 bit pointer, a near is 16 bits. Routines written for one type will not work properly when passed the other type. The compiler should pick this up but I don't know which compiler you are using.

Mike.
 
A far pointer is a 24 bit pointer, a near is 16 bits. Routines written for one type will not work properly when passed the other type. The compiler should pick this up but I don't know which compiler you are using.

Mike.

I'm using MPLAB ICD2.
 
This worked for one of my projects using a Wismo GSM900 module. No worry about near or far pointers. This has worked on both an old MSDOS application using MSVC1.5 and an embedded 68HC11 job without issues using the IAR compiler. Pass the number and message to the function e.g.
sms_message("0798123123","Hello Fred");
send_modem() spews passed data out of the serial port until it encounters a NULL then returns.


/*********************************************************/
void sms_message(unsigned char *num,unsigned char *data)
/*********************************************************/
{
unsigned char str[20]={"AT+CMGS=,"};
unsigned char i;
i=0;

sprintf(modem,"AT\r");
send_modem(&modem[0]);
delay(0.5f);


sprintf(modem,"AT+CMGS=");
send_modem(&modem[0]);


WriteChar(port,'"');
i=0;
while (*(num+i) != '\0')
{
WriteChar(port,(unsigned char)toupper(*(num+i)));
i++;
}
WriteChar(port,'"');
WriteChar(port,CARRIAGE_RETURN);

i=0;
delay(0.5f);



while (*(data+i) != '\0')
{
WriteChar(port,(unsigned char)toupper(*(data+i)));
i++;
}

WriteChar(port,26);



}

/*************************************************/
void send_modem(unsigned char *ch)
/*************************************************/
{
unsigned char i;

i=0;

while ((*(ch+i)) != '\0')
{
WriteChar(port,(unsigned char)toupper(*(ch+i)));
i++;
}

}
 
Last edited:
Hi, thanks for help and advices.

I can send and recevice sms from the modem. I try using 4MHz crystal for circuit oscillator, it works.
But I test using RC for circut oscillator, it won't work. R is 5.1kohm and C is 100pF. Need advice, Thanks.
 
The UART on a micro is very fussy about what baud rate it will use. Often 16x oversampling that with an RC can easily drift out of spec.

This is at both ends, the micro driving and the modem. You need to use a crystal as the modem will only look so far for a compatible baud rate. R &C oscillators will drift and will rarely work. Unless you use a micro with a laser trimmed oscillator.

If it works with a crystal, why are you wasting time with an RC osc? Use a crystal and move on.
 

Hmm, I see. Because for my project I'm doing something like a charging station to charge the battery to get the reading and once it reach 100%, it will send sms to the user.

I use RC osc i can get the reading from the battery, but my modem can't work. If I use crystal, my modem works but can't get the reading.

I set my ADCON2 = 0b10000100 - when using 4MHz crystal, ADCON2 = 0b10000011 - when using RC osc

Is there any other register i need to change?
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…