Hi, I have a question about the Swordfish USART read function when it comes to strings. It seems I can only read 2 ASCII characters from the USART.Read(myString) call. I'm using a PIC18F46K22 which has a 2-byte EUSART receive buffer. I've read most string receiving routines use a circular buffer to store incoming data, and I'd assumed the Swordfish USART library would implement a technique like that, allowing to receive strings of more than 2 bytes length. Unfortunately, the USART.Receive(myString) command becomes permanently blocking if I send a continuous stream of more than two bytes as a string.
But, the USART.Read() function works fine if I manually type into a terminal program (i.e., the character bytes are spaced out by keystroke interval). If I send those bytes continuously, it hangs.
This limitation doesn't depend on the baud rate. I can copy some code here, though I'm guessing there's something I might be missing or that someone else already knows the answer to receiving more than 2 characters as a string with this library module. It seems I should be able to beam a simple "Hello World" + terminator string as a single line transmission and have the USART routine get the whole string. So far all it's willing to receive is "H" + terminator or the terminator alone, if I send the item as a single transmission, though it works if I type each letter (and send them spaced out in time).
Any ideas?
Graham
USART.Read 2-character limit?
Moderators: David Barker, Jerry Messina
-
- Posts: 3
- Joined: Tue Dec 01, 2015 12:08 am
Re: USART.Read 2-character limit?
Look, I get to reply to my own post. The solution here is trivial but I'm sharing in case anyone finds this in the future. The PIC18F46K22 does have a 2 byte receive buffer. I got the string length limit issue by checking
If USART.DataAvailable = true Then ...
in the code, but then calling a few subroutines to prepare data for a response string. The time taken to do that was time enough for the receive buffer to overrun and halt receiving data. I solved the issue by calling
USART.Read(STR_RX)
directly after the If statement, to begin reading the buffer immediately.
Graham
If USART.DataAvailable = true Then ...
in the code, but then calling a few subroutines to prepare data for a response string. The time taken to do that was time enough for the receive buffer to overrun and halt receiving data. I solved the issue by calling
USART.Read(STR_RX)
directly after the If statement, to begin reading the buffer immediately.
Graham
-
- Swordfish Developer
- Posts: 1488
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: USART.Read 2-character limit?
For buffered serial input check out the isrrx interrupt module.
That adds an interrupt driven buffer to the uart input.
That adds an interrupt driven buffer to the uart input.