SIM800L SMS read
Discussion in "Project Help" started by Martinv Feb 11, 2018.
Sun Feb 11 2018, 06:36 pm
Hi All
I am reading an SMS from a SIM800L module. All commands work, I can send an SMS, no problem. When I read an SMS, the module seems to respond too quickly after the CMGR.... command, before the processor is ready (STC12C5604AD). I have tried normal "linear" programming to read the serial port, as well as a serial interrupt routine. With the SMS serial data simulated via another processor, both routines works perfectly. Has anyone come across this issue before? I searched, but did not find anything on this site or any other. Thanks.
The SMS message is typically *1N# or *1F# and the "1" and "N" is filtered and stored in R1 and R2.
CALL READSMS ;This is the CMGR.......routine to the SIM800
CHKSTAR: JNB RI,CHKSTAR ;WAIT FOR *
MOV A,SBUF
MOV B,A ;SAVE A FOR LATER
CLR RI
CJNE A,#02AH,CHKSTAR ;NOT STAR CHR? then LOOP
MOV R0,#03H ;SET CHR TO GET COUNT
;READ ONLY 3 CHRS AFTER *
;ALSO EMERGENCY EXIT IS # IS NOT FOUND
LOOPER: JNB RI,LOOPER ;WAIT FOR NEXT CHR IN
MOV A,SBUF
CLR RI
DJNZ R0,DO ;DO NEXT CHR IF CHR COUNT NOT DONE
JMP DEC ;ELSE DONE, DECODE SMS
DO: MOV B,A ;SAVE A
CHKFIG: ANL A,#030H ;MASK AND CHECK IF FIGURE
CJNE A,#030H,CHKLET ;NOT A FIGURE
MOV R1,B ;SAVE FIGURE
JMP LOOPER
CHKLET: MOV A,B ;MASK AND CHECK IF LETTER
ANL A,#040H
CJNE A,#040H,CHKHASH ;NOT IN LETTER "N" OR "F" RANGE
MOV R2,B ;SAVE LETTER
JMP LOOPER
CHKHASH: MOV A,B ;WAIT FOR # THEN DONE
ANL A,#020H ;MASK AND CHECK FOR HASH
CJNE A,#023H,LOOPER
DEC: JMP DECODE
I am reading an SMS from a SIM800L module. All commands work, I can send an SMS, no problem. When I read an SMS, the module seems to respond too quickly after the CMGR.... command, before the processor is ready (STC12C5604AD). I have tried normal "linear" programming to read the serial port, as well as a serial interrupt routine. With the SMS serial data simulated via another processor, both routines works perfectly. Has anyone come across this issue before? I searched, but did not find anything on this site or any other. Thanks.
The SMS message is typically *1N# or *1F# and the "1" and "N" is filtered and stored in R1 and R2.
CALL READSMS ;This is the CMGR.......routine to the SIM800
CHKSTAR: JNB RI,CHKSTAR ;WAIT FOR *
MOV A,SBUF
MOV B,A ;SAVE A FOR LATER
CLR RI
CJNE A,#02AH,CHKSTAR ;NOT STAR CHR? then LOOP
MOV R0,#03H ;SET CHR TO GET COUNT
;READ ONLY 3 CHRS AFTER *
;ALSO EMERGENCY EXIT IS # IS NOT FOUND
LOOPER: JNB RI,LOOPER ;WAIT FOR NEXT CHR IN
MOV A,SBUF
CLR RI
DJNZ R0,DO ;DO NEXT CHR IF CHR COUNT NOT DONE
JMP DEC ;ELSE DONE, DECODE SMS
DO: MOV B,A ;SAVE A
CHKFIG: ANL A,#030H ;MASK AND CHECK IF FIGURE
CJNE A,#030H,CHKLET ;NOT A FIGURE
MOV R1,B ;SAVE FIGURE
JMP LOOPER
CHKLET: MOV A,B ;MASK AND CHECK IF LETTER
ANL A,#040H
CJNE A,#040H,CHKHASH ;NOT IN LETTER "N" OR "F" RANGE
MOV R2,B ;SAVE LETTER
JMP LOOPER
CHKHASH: MOV A,B ;WAIT FOR # THEN DONE
ANL A,#020H ;MASK AND CHECK FOR HASH
CJNE A,#023H,LOOPER
DEC: JMP DECODE
Tue Feb 13 2018, 02:52 pm
Thanks for the reply. The part of the main loop that must read the SMS, is as below.
WAIT2: mov a,p3 ;read P3 inputs - CHECK RI
anl a,#010h ;mask all but RI P3.4
JNZ WAIT4 ;RI GOES LOW ON RING OR SMS
;check digital inputs meantime
CALL DELAY3 ;WAIT 1 SECOND FOR SMS TO FINISH
;THEN READ SMS
CALL READSMS
JMP DECODE ;DECODE THE SMS
The read routine always reads SMS #1, as I delete all SMS's after a new SMS is received. I have also played with
longer and shorter delays after the read.
The command is AT+CMGR=1 (file types set up etc.) I can confirm the 'read' is understood by the module.
I have a terminal connected to eavesdrop on comms. The read message goes through and within microseconds,
the message is returned by the SIM800. The format is +CMGR: "REC UNREAD"......number, time etc. 'CR' 'LF'
the in the next line *1N# 'CR' 'LF' and OK.
To save on air time, I have programmed a chip with the identical SMS string. When I trigger the event via P3.4
with the second chip and the "SMS string" comes through, the decoder routine reacts perfectly. The only difference
I can think of, is that the SIM800 responds quicker, while the second chip is programmed to respond after a ~second.
Apart from the terminal to monitor port activity, I have no other debug. On an 8051 simulator it also works fine.
I must be overlooking something basic! I have tried a faster clock, it was 11 Mhz and is now 27 Mhz - no change.
Thanks Pal.
WAIT2: mov a,p3 ;read P3 inputs - CHECK RI
anl a,#010h ;mask all but RI P3.4
JNZ WAIT4 ;RI GOES LOW ON RING OR SMS
;check digital inputs meantime
CALL DELAY3 ;WAIT 1 SECOND FOR SMS TO FINISH
;THEN READ SMS
CALL READSMS
JMP DECODE ;DECODE THE SMS
The read routine always reads SMS #1, as I delete all SMS's after a new SMS is received. I have also played with
longer and shorter delays after the read.
The command is AT+CMGR=1 (file types set up etc.) I can confirm the 'read' is understood by the module.
I have a terminal connected to eavesdrop on comms. The read message goes through and within microseconds,
the message is returned by the SIM800. The format is +CMGR: "REC UNREAD"......number, time etc. 'CR' 'LF'
the in the next line *1N# 'CR' 'LF' and OK.
To save on air time, I have programmed a chip with the identical SMS string. When I trigger the event via P3.4
with the second chip and the "SMS string" comes through, the decoder routine reacts perfectly. The only difference
I can think of, is that the SIM800 responds quicker, while the second chip is programmed to respond after a ~second.
Apart from the terminal to monitor port activity, I have no other debug. On an 8051 simulator it also works fine.
I must be overlooking something basic! I have tried a faster clock, it was 11 Mhz and is now 27 Mhz - no change.
Thanks Pal.
[ Edited Tue Feb 13 2018, 02:53 pm ]
Wed Feb 14 2018, 02:56 am
Mmmm feel quite silly, but learned a lot. I must READ properly! The SIM800L hardware specs indicate serial communication as '8N1' and I was running 9 bits. The terminal program is very "flexible" and reads the data correctly with both 8 or 9 bits, but the processor not! That is why the chip-to-chip test worked as well - both at 9 bits. So I changed the SMOD to an 8-bit UART config and walla! I have been around this block for two weeks flat. This piece of code is now also working, so I can link the other sections and tidy up the code. Thanks a lot for your response, it got me thinking harder. Best.
Powered by e107 Forum System