Shop OBEX P1 Docs P2 Docs Learn Events
uart throughput very low — Parallax Forums

uart throughput very low

TyreBiterTyreBiter Posts: 40
edited 2005-09-20 06:09 in General Discussion
sad.gif

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

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-16 06:37
    The highest reliable receive speed is 28800 baud. In a tight loop transmitting

    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
  • TyreBiterTyreBiter Posts: 40
    edited 2005-09-16 16:15
    I'll give it a try at the rate that you suggest and post the source as soon as I get to work tonight.

    Thank you for the input. Peter. By the way do you ever sleep?smile.gif It seems that your replies come very shortly after a posting regardless of the time of day or night....smile.gif

    Regards
  • TyreBiterTyreBiter Posts: 40
    edited 2005-09-17 06:01
    The code in question is in the attachment. The best I could get out of the system is about 400 bytes / second. This is true whether there are two javelins communication or one javelin in loopback mode (tie input to output through a 1k resistor. The suggestion of 28800 baud works wonders. I can abandon the CRC validation of each packet and sequence checking. The code volume on the production system is reduced by 30 to 40 percent. I am not sure that the attachment made it or not.

    AuburnSky
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-17 09:32
    Although you can receive reliable at 28800 (and send reliable at 57600) the throughput is

    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
    ·
  • TyreBiterTyreBiter Posts: 40
    edited 2005-09-19 22:50
    smile.gif

    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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-20 06:09
    900 bytes per seconds sounds allright.

    regards peter
Sign In or Register to comment.