libftdi Archives

Subject: Re: Synchronous Baud Rate Change

From: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Cc: "Owen, Parker (US)" <John.Owen@xxxxxxxxxxxxxxxx>
Date: Tue, 30 Aug 2022 17:38:57 +0200
Hi Parker,

You wrote on Fri, Apr 22, 2022 at 05:22:41PM +0000:
> I am trying to synchronously change the baud rate of one of the ports on the 
> FT4232 chip. What I am trying to do is send out a string of bytes over the 
> UART at baud rate 115200 and then immediately after the string has finished 
> sending change the baud rate to 921600 and start listening. However, the 
> first string of bytes isn't getting sent all the way... What it seems like is 
> happening is the baud rate is changing before the first string is sent all of 
> the way. How do I guarantee the string has been sent fully before the baud 
> rate changes?
> 
> Here is some sample code of what I am trying to do:
> 
> ftdi_set_baudrate(ftdi, 115200);
> ftdi_write_data(ftdi, outBuf, size); // fails to send fully before baud rate 
> changes to 921600.
> ftdi_set_baudrate(ftdi, 921600);
> numBytesRead = ftdi_read_data(ftdi, inBuf, size);
> 
> 
> Any ideas on how to fix this?

hmm, I'm not sure such tricks are possible.

The chip has functionality to purge the read and write buffers, but that will 
clear the data and not make sure it has been sent out.

USB transmissions are packet based, so in case of CRC checksum error,
the host controller will send the packet again. One could calculate the
length of the sent string and the baudrate speed and then sleep for
a certain time, but such tricks are all unclean and will fall
apart sooner or later. Probably sooner. ^^

Cheers,
Thomas

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread