Page 1 of 1

ReadSerial Issue

Posted: Mon Apr 14, 2008 2:44 pm
by Widgetman
Hi All,
I am using the Read Serial routine listed below with some tweaks. I an running a counter and when I see two bytes in a row of a certain pattern I allow the counter to increment to a value of 2. Any other time it should be either 1 or 0. the issue I have is my count of 2 never fires and yet I know it should with my incoming data. Any ideas why Count would never reach 2 if my pattern comes in ?
Thanks

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
If RXData(SDataSize-1) = $14 Then
Count = 1
Else
Count = 0
EndIf

If (RXData(SDataSize-1) = $63) And (Count = 1)Then
Count = 2
EndIf

End Sub

Posted: Mon Apr 14, 2008 3:46 pm
by RadioT
How about adding a debug statement to screen or serial port that shows the value of RXData(SDataSize-1) , ByteCount and Count to verify the numbers are as expected? Maybe there is an extra carriage return or something unexpected coming in.

-Tom

Posted: Mon Apr 14, 2008 5:11 pm
by Widgetman
Hi RadioT
I thought about that but th4e RX routine is interrupt driven and really fast. I have a continious stream also of data @115200 so that makes a debug line hard. I was hoping someone had used this function b4 and knew it better than me.

Posted: Mon Apr 14, 2008 9:28 pm
by xor
Slow it down ( a lot) and then debug it and work up the speed in steps. That will tell you something, whether code problems right away, or other possible propagation delays and/or (a)synchronization problems causing problems at high speed.

Check the datasheet for the percentage error at your oscillator and BRGH settings. A change in oscillator speed can sometimes land you in better asynch error conditions.