ReadSerial Issue

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

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

ReadSerial Issue

Post by Widgetman » Mon Apr 14, 2008 2:44 pm

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 ?

Sub ReadSerial()
Dim Index As Byte
SDataSize = 0
While ISRRX.DataAvailable
SData(SDataSize) = ISRRX.ReadByte()
Inc (ByteCount)

If SDataSize > 0 Then
For Index = 0 To (SDataSize - 1)
RXData(Index) = SData(Index)
If RXData(SDataSize-1) = $14 Then
Count = 1
Count = 0

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

End Sub

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

Post by RadioT » Mon Apr 14, 2008 3:46 pm

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.


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

Post by Widgetman » Mon Apr 14, 2008 5:11 pm

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.

Posts: 286
Joined: Sun Nov 05, 2006 1:15 pm
Location: NYC

Post by xor » Mon Apr 14, 2008 9:28 pm

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.

Post Reply