At 3:40 PM -0500 2000/05/16, Steve Branin wrote:
>// set the baud rate to 9600
>rate = 9600;
>err = SrmControl(portID, srmCtlSetBaudRate, &rate, &ratesize);
>
>// copy my string into the send buffer and send it
>StrCopy(sendBuffer, "This is a test.");
>dataSent =  SrmSend(portID, &sendBuffer, 15, &err);
>
>//flush the FIFO
>SrmSendWait(portID);
>
>// change the baud rate to 4800
>rate = 4800;
>err = SrmControl(portID, srmCtlSetBaudRate, &rate, &ratesize);
>
>When I do this, 95% of the time the end of my string is truncated.  If I
>introduce a delay after the SrmSendWait then the code works fine.  I suspect
>that the SrmSendWait function isn't doing what it is supposed to...or else I
>am misunderstanding what it is supposed to do.  Can anybody shed some light
>on this?

When switching baud rates, it's not at all uncommon for the first one or two bytes 
following the rate change to be received by the other UART as "garbage" bytes, and 
almost always with framing errors (parity, start and stop bits). It really depends on 
how quickly the receiving UART is able to re-synchronize to the new bit rate. If this 
were some other bit stream encoding method (like HDLC for example) the receiver would 
know instantly that a bit rate mismatch occurred, and at which byte. But with 
"standard" RS-232 N-8-1 style encodings, this sort of problem is very common; not 
unique to the Palm OS or Palm devices.

It looks to me like what's happening is the Palm is waiting until it's send buffer is 
completely empty, and the receiving FIFO is being filled with the data you sent from 
the Palm. But before the receiver can pull the data out of its FIFO, you change the 
bit rate, which signals a framing error on the receiver. The receiver then dumps its 
entire FIFO rather than just the one most recently received byte containing the 
framing error, and thus your sent data appears to have been truncated by however many 
bytes were left in the receiver's FIFO.

There's no really clean solution to this problem except to introduce hard-coded 
delays. Except, of course, implementing some sort of reliable datagram protocol over 
that serial connection... like MNP... or IrCOMM... or... :oP

Regards,

Jim Schram
Palm Incorporated
Partner Engineering


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to