USART Charcter Comparison

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

USART Charcter Comparison

Post by Widgetman » Sat Jan 19, 2008 4:24 pm

Hi All,
I am stumped on trying compare characters coming in from the USART. I thought I understood it the other day when I asked about it but I guess I don't. Listed below is what I tried but I think my issue is I am trying to compare a HEX constant to a character coming in, and I can't seem to figure out how to convert the character coming in as a hex byte. I am using the ReadSerial() routine to get the characters from the UART. Any help would be appreciated
Thanks

Public const TEST(4) as byte = ($42 $4F $4F $54) // Ascii "BOOT"


// Read serial port
Sub ReadSerial()
Dim Index As Byte
SDataSize = 0
While ISRRX.DataAvailable
SData(SDataSize) = ISRRX.ReadByte()
Inc(SDataSize)
Inc (ByteCount)
Wend

If SDataSize > 0 Then
For Index = 0 To (SDataSize - 1)
RXData(Index) = SData(Index)
Next
EndIf
End Sub



While ByteCount <= 3 // Sits And Waits For The BOOT string to come in
ReadSerial
Wend

For I = 0 To 3 Step 1 // Loop Thru All 4 Charcters To Verify Them

If SData(I) = Boot(I) Then
Inc (BytesCorrect,1) // If Charcter Matched Increment Counter
Else
Goto END // If Charcter Fails Exit
Endif

Next
Last edited by Widgetman on Sun Feb 24, 2008 3:35 pm, edited 1 time in total.

User avatar
RadioT
Registered User
Registered User
Posts: 157
Joined: Tue Nov 27, 2007 12:50 pm
Location: Winnipeg, Canada

Post by RadioT » Mon Jan 21, 2008 12:47 pm

Hello,

I'm working with deciphering serial data myself, so I'm interested in helping out with this, as it may help me answer some questions of my own that I have had. First note, I recommend looking over the NMEA module, as it provides a working example of how to read in a serial port stream and do the comparisons. This is in the Wiki section ( http://www.sfcompiler.co.uk/wiki/pmwiki ... hUser.NMEA ).

Next, I can see what you're doing in general, that you are working byte-by-byte to do the comparisons. How about using the sample code under Interrupt_OnData.bas that used the Event OnData in the USART interrupt? In this Event, you automatically have the current byte defined and can make the necessary comparisons. Of course, this is all done within an interrupt, so you want to make sure you keep it as simple as possible and context save if necessary so there is no curruption of other code.

Now, looking at the code that was posted. The first thing that struck me was the fact the public const statement on the first code line didn't have commas between each value. Maybe you had to transpose the code to the forum page and didn't remember to put them in, but anyway, after making the correction and attempting to compile the code I see a problem with the statement:

Code: Select all

Else 
Goto END // If Charcter Fails Exit 
Endif
This won't work unless you have a label specifically named "end".

After I replaced "goto END" with "exit", which causes a loop to exit, I found that "SDataSize = 0" is given without SDataSize being first declared. OK, I set it up at "Dim SDataSize as Byte" in the function.

Then I ran into another error, where

Code: Select all

SData(SDataSize) = ISRRX.ReadByte()
I see that you assign a byte of data read in by ISRRX.ReadByte() to an array element number SDataSize in array SData. But SData has not been declared...again, it looks like the cut-and-paste of the code example didn't all get in there. After I declared SData as an array at the top of the main code body as "Dim SData(5) as Byte" (5 bytes is enough, isnt it?), I get the error that ByteCount is not declared. OK, I declared that as a byte, "Dim ByteCount as Byte". And again with RXData, declared that as an array as with SData, then "I", as byte. Then I come up against "Boot75" and then have to stop. I have no idea what "Boot75" is to mean.

-Tom

Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

Post by Widgetman » Mon Jan 21, 2008 7:03 pm

Hi Tom,
Sorry about the errors, I am still trying to work this out. Listed below are some answers to your questions. Thanks for the link

1 BOOT75 should be BOOT which is a 4 charcter Respresenation I am looking for on the incoming stream

2 When I was testing this I made a buffer of 16 bytes for the SDATA(16)
I also made the TXBuffer and RX Buffer as 16 bytes since I know how many charcters are coming in at a time for my specific application.

3 As of yet I still have not figured this out but I am close
I will post what I find when I get it working

Post Reply