The problem is in the way you have structured your program. You are assuming that:
- Code: Select all
while Uart2.DataAvailable = true
b(nxtStr) = Uart2.Readbyte()
nxtStr += 1
end while
will read the whole string in. However, the loop is so fast that "DataAvailable" will return false (as the next character has not been received) - so it falls through to the uart output loop. In the meantime, more data is being received via uart2 but nothing is processing it, so you get a buffer overrun and uart2 will stop processing any further data until the overrun flag is cleared. You need to look for a line terminator before exiting the loop. For example:
- Code: Select all
dim b as string(256)
dim nxtStr as ushort = 0
dim data as byte = 0
do
data = Uart2.Readbyte()
b(nxtStr) = data
nxtStr += 1
loop until data = 13
I've checked this code and your routine now works as expected.
Personally, when reading data in from a uart (either 1 or 2), I prefer to use an interrupt that buffers data when it arrives. This way, you never miss a thing and your program can do other stuff without worrying about servicing the uart. There is an example included in the Firewing installation that does just this for uart1. It would be a very trivial task you make another module based around this code so it supported uart2 (the GPS module will also help in determining what flags to set as this module buffers data from uart2)