Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Storing text received from usart

Status
Not open for further replies.

pixman

Member
Hi

I am working on a gsm project. I can send all the AT commands to the gsm modem(u-blox leon g-100). Sending an sms has not been a problem.

The problem i do have is receiving from the gsm modem.
If i send the command AT, it returns OK. i want to read this in and check that OK was sent before sending the next command. If i do not check for the returned text i will not know if there was an error and the commands will keep sending and nothing will happen due to the error.

Once i can get this working, I would like read in a text measage sent to the gsm and switch on a output on the pic depending on the measage received.

In another post i got help on how to compare the text, but i have NO idea how to read the info in from the usart and the process it.

I am using a pic18f4520 and assemble.

Please help i have been struggling now for 5 days and it is getting me down.
:(
 
Last edited:
Check out the CNMI command

Code:
String8
    dt  "AT+CNMI=1,2,0,0,0", CR, LF, 0 ; output full txt message
    ;dt  "AT+CNMI=1,1,0,0,0", CR, LF, 0 ; output index number of txt message

It sets what is sent from the modem in response to a text message.

I simply read the entire text message into a GPR buffer, and then compare from there.
 
Something like,
Code:
;use bank 2
	cblock	0x110
Buffer:96
	endc


	call	SendAT
	movlw	Buffer		;get low byte of address
	movwf	FSR		;use as pointer
	bsf	STATUS,IRP	;use banks 2&3
loop	call	Receive		;get byte
	movwf	INDF		;store it
	incf	FSR,f		;inc pointer
	xorlw	0x0a		;was last char 0x0a
	btfss	STATUS,Z	;skip if so
	goto	loop		;else loop

; should now have "Received string",0x0d,0x0a in buffer

The above assumes that something like a 16F88 is used (96 bytes in bank 2).
The string ends with carriage return, linefeed. (0x0d, 0x0a).
The received string is less than 96 bytes long.

Mike.
 
Hi Mike

I put the code into what is left of the program and when i did a reduild it came up with errors.

Error[113] I:\PIC18F4520 GSM\RS232 GSM.ASM 100 : Symbol not previously defined (FSR)
Error[113] I:\PIC18F4520 GSM\RS232 GSM.ASM 101 : Symbol not previously defined (IRP)
Error[113] I:\PIC18F4520 GSM\RS232 GSM.ASM 103 : Symbol not previously defined (INDF)
Error[113] I:\PIC18F4520 GSM\RS232 GSM.ASM 104 : Symbol not previously defined (FSR)

Is this because it is 18f4520
 
Just realized your using an 18F chip, the above if for 16F. You should be able to use it by using FSR0 and INDF0 etc. I'm just on my way out so don't have time to change it but if you're still struggling tomorrow I'll update it.

Edit, read the section on "indirect memory addressing" to work out how to change it. Got to run.

Mike.
 
Last edited:
Hi Mike

Changed the example and put it into a small test program. I am not to sure if it is working. I ran it with hyperterminal and mplab Debugger with pickit2 when i look for the text string, i can't find it. I have attached my code. please have a look and let me know if there is a problem.
 

Attachments

  • RS232 GSM.ASM
    5.8 KB · Views: 200
could somebody please tell me were to find info on indirect memory addresing.
looked in the data sheet for pic18f4520 but not enough info for me to understand.
looked in microchip embedded control hand book but examples are in c
searched microchip site and can not find something helpful.
 
I'm just on my way out again (7pm Friday here - yippee) but tomorrow I'll try and find time to knock up an example.

Mike.
 
Thanks Mike

There is an 8 hour time diffrence. I will continue trying diffrent things. looking forward to your reply.
 
Pixman! I see you're from SA Germiston... I've been there... I lives in Witbank for 5 years... Nice country...

Anyway... Have you ever though of learning C? strings are soooo much easier in a higher level language.
 
Hi Ian

I want to learn C, but i will be like strating over again. I have found a book called :C WHAT HAPPENS" (using pic microcontrallers and ccs c compilier). I would like to finish of the project I am working on then give C ago.
Any other resources to help and tutorials would be welcome.
 
Here's an example that loads the buffer with a string (Mess) and then searches a list of strings to find a match.
Code:
        	include <P18F1320.INC>

		cblock	0x80			;start of general purpose registers
buffer:128
		endc

		cblock	0x0
count
Pointer					
		endc

ResetVector     org    0x00
	
	call	SendAT		;resets pointer
	movlw	low buffer
	movwf	FSR0L
	movlw	high buffer
	movwf	FSR0H
Loop	call	Get232		;reads from Mess
	movwf	INDF0
	incf	FSR0L,f
	xorlw	0x0a
	btfss	STATUS,Z
	goto	Loop

	call	Search

hang	goto	hang

	
Search	movlw	upper mess
	movwf	TBLPTRU
	movlw	high mess
	movwf	TBLPTRH
	movlw	low mess
	movwf	TBLPTRL
	clrf	count
loop	tblrd*
	infsnz	TABLAT,w	;test for end of table
	goto	done
	movf	TABLAT,W	;skip any zeros
	bnz	NotZero
	tblrd*+
	bra	loop
NotZero	movlw	low buffer
	movwf	FSR0L
	movlw	high buffer
	movwf	FSR0H
Compare	tblrd*+
	tstfsz	TABLAT
	goto	Contin
;found match
	incf	count,w
done	return
Contin	movf	POSTINC0,W
	xorwf	TABLAT,W
	bz	Compare
;no match
skip	tblrd*+
	tstfsz	TABLAT		;test for end of message
	goto	skip
	incf	count,F
	goto	loop
	


mess	db	"on motor1",0
	db	"off motor1",0
	db	"on motor2",0
	db	"off motor2",0
	db	0xff	

SendAT	clrf	Pointer
	return

Get232	movlw	low(Message)
	addwf	Pointer,w
	movwf	TBLPTRL
	movlw	high(Message)
	btfsc	STATUS,C
	addlw	1
	movwf	TBLPTRH
	movlw	upper(Message)
	btfsc	STATUS,C
	addlw	1
	movwf	TBLPTRU
	tblrd*
	movf	TABLAT,w
	incf	Pointer,f
	return
	

Message	db	"on motor2 and somert else",0x0d,0x0a
	db	0

	END

In this case it matches string 3 and so W=3 when it hits the hang line.

I've not commented the code as I was in a rush. Try stepping through it in the simulator and see if it makes sense to you.

Mike.
 
Ran the section in sim and understand you first load measage 'on motor2 or somert else' in to buffer, then you compare that with the four text strings when it finds one that is a match to the whole string 'on motor2' then ends.
just a small question. can you see the whole string stored in the buffer as one string.
 
Never mind, stupid question, I looked in VIEW, FILE REGISTERS 080 and there is was.
The next dumb question, Can you clear the Register without writing to it.
 
MIKE
I have been playing around with it for a while now. And figured out that if a incorrect text string is found the WREG will have zero in it. If a correct text string is found then the WREG will have the correct look table number in it. This been said, you should be able to compare 255 text strings. Am i correct in saying this.
I am very greatful for your help, and THANK YOU for the help. Ihave learnt alot with this code you gave me.
1. How to use tables to send a message
2. How to put a texr string or value into a buffer
3. How to compare to diffrent value.

Once again "THANK YOU'

David
 
Status
Not open for further replies.

Latest threads

Back
Top