Serial communication speed
I have an application where 2 Javelins are communicating with each other via Uart VPs. Problem I'm having is overall communication speed.
A condensed version of one side of the communications looks like this:
· public static boolean Init()
· {
··· .
··· .
··· .
··· txUart = new Uart( Uart.dirTransmit,
····························· CPU.pin2,
····························· Uart.dontInvert,
····························· Uart.speed38400,
····························· Uart.stop1 );
··· .
··· .
··· .
· }
· public static boolean SendCommand()
· {
··· .
··· .
··· .
· · for( int i = 0; i <= 6; i++ )
· · {
· ··· txUart.sendByte( commCmd[noparse][[/noparse]i] );
··· }
··· CPU.delay( 60 );······· // Wait for data to be sent.
··· .
··· .
··· .
· }
Looking at the output of CPU.pin2 with a logic analyzer, it take 2.5 milliseconds·before the first·byte·starts. Each byte takes the expected 260 microseconds, then 2 millisecond between each successive byte. At this pacing, it take about 14 milliseconds to send 6 bytes, for an effective baud rate of 428!!! Nowhere near the 38400 we're looking for.
Any clues as to what may be happening?
TIA
Steve
·
A condensed version of one side of the communications looks like this:
· public static boolean Init()
· {
··· .
··· .
··· .
··· txUart = new Uart( Uart.dirTransmit,
····························· CPU.pin2,
····························· Uart.dontInvert,
····························· Uart.speed38400,
····························· Uart.stop1 );
··· .
··· .
··· .
· }
· public static boolean SendCommand()
· {
··· .
··· .
··· .
· · for( int i = 0; i <= 6; i++ )
· · {
· ··· txUart.sendByte( commCmd[noparse][[/noparse]i] );
··· }
··· CPU.delay( 60 );······· // Wait for data to be sent.
··· .
··· .
··· .
· }
Looking at the output of CPU.pin2 with a logic analyzer, it take 2.5 milliseconds·before the first·byte·starts. Each byte takes the expected 260 microseconds, then 2 millisecond between each successive byte. At this pacing, it take about 14 milliseconds to send 6 bytes, for an effective baud rate of 428!!! Nowhere near the 38400 we're looking for.
Any clues as to what may be happening?
TIA
Steve
·
Comments
is about 1000 chars per second, so the effective throughput
is around 10000 bits per second, or 9600 baud, although the
bytes themselves are transmitted at 38400 baud.
Since the bytes must be read from the uart buffer before being sent,
I expect the time required to empty the uart buffer to be doubled,
so the throughput as seen from outside the javelin is 500 chars per second.
That is consistent with your findings.
Note that your javelin program already continues after 6 mlliseconds, not 12,
(so the uart buffer is emptied while your javelin program continues)
regards peter
Steve
http://tech.groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/core/
I redefined the Uart buffer as a public char array
and added a method bufferSet() so you can·fill the array directly.
The original Uart class has the uart buffer declared as a private int array,
using javelin code to split integers into bytes and store them,
and that does not help throughput speed.
regards peter
Thanks for the new uart class, speeded things up a bunch. I never really thought about modifing the base classes, so I took your lead and made a few more changes specific to my environment. Now I have communications running at darn near 38.4K.
Thanks again
Steve
If you make improvements and would like to share these,
then please post your adapted classes. If they are really
useful we can all benefit from them.
regards peter