uart throughput very low
TyreBiter
Posts: 40
I am working on a project that uses the uart function to communicate between two javelin stamps on BOE boards. What I am finding is that the effective throughput is on the order of 200 bytes per second even at a baudrate of 57600.
My byte rate approximation is arrived at by writing a fixed buffer of 64 bytes and then reading the input if it is available. i.e. write, read .... write, read with no processing being done other that keeping track of the transmission record count, receive record count and total byte count received and at the end of 20 seconds displaying the data.
I must be missing something critical. This seems to be a very low effective transmit/ receive rate. I am using the modified version of the uart function to speedup the process.
Thank You for you time in advance...
AuburnSky
Comments
gives about 10 kbit (or 1000 chars/s) burst throughput. Displaying (I assume
using System.out) takes quite some time and will decrease the effective
throughput. Can you post your mainloop so to show what·exactly you do
besides transmitting/receiving?
regards peter
Thank you for the input. Peter. By the way do you ever sleep? It seems that your replies come very shortly after a posting regardless of the time of day or night....
Regards
AuburnSky
limited to about 10 kbit/s (due to ram copying), so unless forced to use a higher baudrate
(by the external device)
I would suggest to use 9600 baud or lower. The lower the baudrate, the less CPU cycles are spent
in the interrupt service routine, the faster the mainline code is executed.
Your read() appends to a StringBuffer. This all takes quite a lot of time.
In my adapted Uart class (you said you used an adapted uart class, so··I assume its mine)
there are already methods for reading character arrays, which are faster than the String
methods.
·· /**
·· * Receive a String.
·· *
·· * @param data the character array to hold the string.
·· * @param num Maximum number of bytes to receive.
·· * @param offset Index in data to start from.
·· * @return The number of bytes actually placed into data.
·· */
· public int readString(char[noparse]/noparse data, int num, int offset) {
· /**
·· * Receive a String. This method blocks until num characters are received.
·· *
·· * @param data the character array to hold the string.
·· * @param num Maximum number of bytes to receive.
·· * @param offset Index in data to start from.
·· */
· public void receiveString(char[noparse]/noparse data, int num, int offset) {
There is also a write character array method
· /**
·· * Transmits a String.
·· * This method returns -1 if there is not enough room in the buffer
·· * to hold the string.
·· *
·· * @param data the string to transmit.
·· * @param num Number of bytes to transmit.
·· * @param offset Index in data to start from.
·· * @return The number of bytes transmitted or -1.
·· */
· public int writeString(char[noparse]/noparse data, int num, int offset) {
Also, the uart transfer buffers are public. So you can fill up the transmit buffer (start filling it up
when it is empty, start at head position). Once filled, simply set the head parameter. See method
· /**
·· * Set the number of bytes in the buffer.
·· * This method is intended to set the number of characters
·· * in the buffer AFTER the buffer has been filled.
·· * Before filling the buffer it should be empty.
·· *
·· * @param bytes The number of bytes to transmit.
·· *······· The number of bytes in the buffer equals head-tail.
·· */
· public void bufferSet(int bytes) {
You find my adapted uart class here
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/core/
The adavantage of direct buffer access is to avoid the extra copying of data that is otherwise
required. The disadvantage is you must wait for the transmit buffer to be empty before filling it
up again (starting at head position)
regards peter
·
Peter;
I stripped the read function to just clearing the uart's input buffer and got about 900 bytes per second
at both 9600 and 4800 baud.
Thansk for the input...
AuburnSky
regards peter