AT commands GSM, Receive sms, need help!

Tobias Simonsen

New Member
Hi,

Using a SIM800L GSM module connected to a 08M2 chip.
Everything is connected and works as it should.
I can send SMS from the setup, no problems.
I can receive SMS, but I can not get the information out of the SMS.
The setup is connected to a Hyperterminal on my computer, so I can see what is going on.

I can see the SMS is received in the Hyperterminal. It is a long string in one line (including sender number, date, time ect.), and the next line contain the SMS text.
I need that text, to be used in the code, so eg. when I send "1" (the number one), my code should check for this "1", and if it is correct then jump to another place in the code.

Below is the start of my code:

pause 500
serout c.1,T2400,("AT+CMGD=1",CR)
pause 2000
serout c.1,T2400,("AT+CMGF=1",CR)
pause 2000
serout c.1,T2400,("AT+CSCA=",$22,"+4540590000",$22,CR)
pause 200
serin c.4,T2400,("+CMTI:")
pause 200

main:
if pinc.3 = 1 then sendsms
serout c.1,T2400,("AT+CMGL=",$22,"ALL",$22,CR)
serin c.4,T2400,("+CMGL")
serin c.4,T2400,(LF)
serin c.4,T2400,W0
if W0="1" then switch_on
goto delete

_________________________________

It is in the main program I have the problem, I think.

The AT+CMGL=ALL command list all the SMS which is received by the GSM module.
The +CMGL command is waiting for +CMGL to be shown before it goes on. Then I made a Line Feed, I then the first letter/number in the second line should be put into the W0 register, and if W0=1 then jump to "switch_on".

The Hyperterminal shows:

AT+CMGL="ALL"
+CMGL: 1,"REC UNREAD","+4520730587","","17/02/11,08:18:55+04"
1

How do I get the 1 into the W0 register?

I think I am missing an AT command or what do I do wrong?

Thanks a lot for your help.
 

hippy

Technical Support
Staff member
It could well be that the PICAXE is not fast enough to find the "+CMGL", the LF and ready to read the number before that's already been sent and missed.

One would ideally use an X2 PICAXE and background receive to handle variable length and back-to-back data but it may be possible to issue the command then wait for the LF and read the number -

serout c.1, T2400, ( "AT+CMGL=", $22, "ALL", $22, CR )
serin c.4, T2400, ( LF ), #w0

It might also help to increase the PICAXE operating speed and adjust the baud rates -

setfreq M16
serout c.1, T2400_16, ( "AT+CMGL=", $22, "ALL", $22, CR )
serin c.4, T2400_16, ( LF ), #w0
 

Tobias Simonsen

New Member
Hi Hippy,

Thanks for you suggestions, but nothing work :(

I have tried to write the lines you have suggested, and also tried with a 20X2 chip.

It is really hard to get it to work. Do you have any suggestions on how I can go on?

I need to make a code, which can detect a sms, and read the content of the sms, which so can be used in the code.

How do I make it to backgound receive?
 

hippy

Technical Support
Staff member
Here is how I would start with background receive. It issues the AT command, waits a couple of seconds for whatever comes back which gets put in the scratchpad / background receive buffer, then prints that out -

Code:
#Picaxe 20X2
#Terminal 9600
HSerSetup B2400_8,%001
Pause 2000
SerTxd( "Started ...", CR, LF )
Do
  HSerOut 0, ( "AT+CMGL=", $22, "ALL", $22, CR )
  Pause 2000
  Do While ptr <> hSerPtr
    SerTxd( @ptrInc )
  Loop
  SerTxd( CR, LF, "---", CR, LF )
Loop
 

Tobias Simonsen

New Member
Hi,

Hm, thanks.

That code is way above my knowledge of the Picaxe code.
I will try to write that code and see what happens.
But which pins are used for serin and serout? Can I see that in that code?
And where can I find the result of the sms? Is it put in a register (eg. w0?)?
I will give it a try, and sorry for my bad knowledge of the code.
As long that I can get it to work, I would be happy.
The only part of my code, where it do not work, is this part where I want to receive a sms.
Thanks for your help, it is very very useful!
 

BESQUEUT

Senior Member
But which pins are used for serin and serout? Can I see that in that code?
Not serin/serout but Hserin / Hserout/ HSerSetup
H mean Hardware, so there is only one pin for hardware serial receive.
For 20X2, look at manual 1 page 30 :
pin #10 (C.0) = HSEROUT
pin #12 (B.6) = HSERIN
 

hippy

Technical Support
Staff member
And where can I find the result of the sms? Is it put in a register (eg. w0?)?
That code will not extract the SMS code. It will only display what comes back from the module in response to the AT command.

If that works as expected, the code can be improved to make it more efficient and responsive. Once the improved code is proven to work that can be extended to extract the SMS data you wish to use.
 
Top