PDA

View Full Version : enfora gsm to pic 16f877



starwick
- 3rd October 2010, 16:01
Hi,
First of all i would like to thank everyone in this forum for their help and support, This form helped me a lot and i thank you for it.
i Just bought an enfora rs232 gsm modem which i tested with hyperterminal at baud 9600 and i was able to send sms as well as receiving tried a lot of AT command 100% working.
I have succeded to conect my pic(16f877) to rs232 using serout2 and serin2 without max232 using the hardware inverter(baud=16468), Every project with pic to rs232 has been a succes!!.
Now i want to connect the modem to my pic and all went wrong, Here what i tried:

1) set the pic baud=84 for non inverted(9600) to talk to the mode no luck(no max232,since the modem talking to the serial port then no need for inverter)
1)baud=16468 same as above
2)on the gsm rs232 i tied pins 1,4,6 and 7,8(handshaking) no luck

i read a lot of post here regarding gsm and i noticed most of the codes using hserout which required max232 why not using serout2 with inverted or debug?
Also most of the posts recommend using 20mhz i'm only using 4mhz will that cause a problem? i think since the modem is working 100% at 9600 baud using hyperterminal it should work with the pic @9600.
Any help is appreciated.This this my first post so please help!!!!
Best regard,

mackrackit
- 3rd October 2010, 17:36
4MHz is border line for 9600 baud. That is mentioned in the manual.

Other problems could be in your code. You need to post it so the GSM guys can see what you are doing.

starwick
- 5th October 2010, 05:29
Hi,
Thank for the reply. As for the code i'm just using a simple code to check the modem respose(OK):
Include "modedefs.bas"




'***************************LCD DEFINE*******************************
DEFINE LCD_DREG PORTD 'LCD data port
DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTD 'LCD register select port
DEFINE LCD_RSBIT 4 'LCD register select bit , RS=PORTC.4
DEFINE LCD_EREG PORTD 'LCD enable port
DEFINE LCD_EBIT 5 'LCD enable bit E=PORTC.5
DEFINE LCD_RWREG PORTD 'LCD read/write port
DEFINE LCD_RWBIT 6 'LCD read/write bit R/W=POTRA.1
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 4 'Number lines on LCD
DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50

'************************************************* *****************

ADCON1 =7

TRISA = $FF
TRISB = 0
TRISC = 0
TRISD = 0
TRISE = 0
LCDATA VAR BYTE(8)
CLEAR
PAUSE 1000
LCDOUT $FE,1
LCDOUT $FE, 2
LCDOUT " STARWICK GSM V1.0"


MAIN:


serout2 PORTC.6,84, ["AT",13,10]
SERIN2 PORTC.7,16468, [WAIT("OK")]


LCDOUT $FE,$C0
LCDOUT "OK"
SEROUT2 PORTC.6,84,["AT+CMGR=1",13,10]
SERIN2 PORTC.7, 84,[STR LCDATA\8\13]
LCDOUT $FE,1
LCDOUT $FE,2
LCDOUT STR LCDATA\8
PAUSE 3000
GOTO MAIN

END

I don't get any response from the modem. i also tried SERIN2 PORTC.6.84,[STR LCDATA\2] And display LCDATA with no luck. Thanks for any help.

starwick
- 5th October 2010, 08:46
so far i was able to send A TEST sms via the pic from the gsm modem no max232 4mhz 16F877 below is the code:

MAIN:
Serout2 PORTC.6,16468, ["AT",13,10]

SERIN2 PORTC.7,16468,[WAIT ("OK")]


LCDOUT $FE,$C0
LCDOUT "SENDING MESSAGE..."
SEROUT2 PORTC.6,16468,["AT+CMGS=",34,"18155295213",34,13,10]
PAUSE 1000
SEROUT2 PORTC.6,16468,["TEST FROM PIC",13,10]
PAUSE 1000
SEROUT2 PORTC.6,16468,[26]
LCDOUT $FE,$C0
LCDOUT "MESSAGE SENT "
PAUSE 1000
END

Now corredct me if i'm wrong the pic will not pass the second line of the code(SERIN2 PORTC.7,16468,[WAIT ("OK")]) unless it received OK is that coreect? That means that the pic is receiving the correct chars from the gsm correct?
will try to send and read to an array.
Thanks for any response or help....

Best regards,
Joe

mackrackit
- 5th October 2010, 09:28
Now corredct me if i'm wrong the pic will not pass the second line of the code(SERIN2 PORTC.7,16468,[WAIT ("OK")]) unless it received OK is that coreect?
That is correct.

starwick
- 5th October 2010, 12:42
Thanks a lot for the response.
Here is the latest i was able to receive a text messege,TIME, caller id(C_ID) and dispaly the exact length of the message.
I don't know why but it seems that the modem is responding with the commands i send first then the answer for ex :
SEROUT2 PORTC.6,16468,["AT+CMGR=1",13,10]
the modem will respond AT+CMGR=1 THEN the rest (+CMGR: "REC........"), I found that by making LCDATA var byte(80) and display all 80 chars received(max chars in my 20x4 lcd), But the modem will not do that with hyperterminal if you enter AT+CMGR=1 in hyperterminal the response will be ERROR if no messages or +CMGR:....., So i decided to just look for READ after AT+CMGR=1 and... and it worked.rs232 at the modem side is 4=6 and 7=8 before i tried 1=4=6 but the modem didn't respond at all.
************************************************** **************
MAIN:



serout2 PORTC.6,16468, ["AT",13,10]

SERIN2 PORTC.7,16468,[WAIT ("OK")]




SEROUT2 PORTC.6,16468,["AT+CMGR=1",13,10]'read messaage at SIM #1
SERIN2 PORTC.7,16468,[wait ("READ"),SKIP 4,STR C_ID\11,SKIP 4,STR TIME\17,SKIP 6, STR LCDATA\20\10]

LCDOUT $FE,1
LCDOUT $FE,2
LCDOUT STR TIME\17 'display date and time
FOR J=1 TO 20
IF LCDATA(J)=13 THEN' wait for 13 char then put in LA where la is length of the message
LA=J
GOTO GOTLA
ENDIF
NEXT J
GOTLA:
LCDOUT $FE,$C0
LCDOUT "SMS LA=", DEC LA ' display the length of the message
LCDOUT $FE,$D4
LCDOUT STR LCDATA\LA'display the message
END
************************************************** ****************
since i got the WAIT command to work and i used it to read the messages, I don't care if it is read or unread for now i only sent one message and i try to read it. Still having problem with the connection between the pic and the modem with the above setup will work but when i turn the
power off it may work or not then i try again and it will work, I don't know if it's a speed problem as you mention before or just a loose connection(breadboard)...

Once again thank for any help


Best regards,
Joe