libftdi Archives

Subject: Re: Problems with FT232R in bitbang mode

From: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Wed, 19 May 2010 14:26:14 +0200
On Tuesday, 18. May 2010 19:03:47 Helge Lenz wrote:
> Lets take a very simple example:
> ------------------------------------------------------------
> #include <stdio.h>
> #include <ftdi.h>
> #include <sys/time.h>
> int main(void)
> {
>   struct ftdi_context ftdic;
>   unsigned char testbuf[3];
>   testbuf[0]=0;
>   testbuf[1]=255;
>   testbuf[2]=0;
>   ftdi_init(&ftdic);
>   ftdi_usb_open_desc(&ftdic, 0x0403, 0x6001, NULL, NULL);
>   ftdi_set_bitmode(&ftdic,0xFF,0x01);
>   ftdi_set_baudrate(&ftdic,9600);
>   ftdi_write_data_set_chunksize(&ftdic,3);
>   while (!0)
>   {
>         ftdi_write_data(&ftdic,testbuf,3);
>   }
>   ftdi_usb_close(&ftdic);
>   ftdi_deinit(&ftdic);
>   return 0;
> }

Oh yes, of course, if you send everything in one buffer,
then it should theoretically always work. Though you have to make sure
you use only one ftdi_write_data call() for that. The internal
packet size is 64 bytes for the old chips and 512 bytes
for the new hispeed chips.

> ------------------------------------------------------------
> Is there something wrong with this example (except from checking return
> values etc...)? What am I going to measure with my scope? I would say I
> should measure a peak of 6.51 µs according to FTDI specs (baudrate * 16)
> or 13.02 µs according to other specs (baudrate * 8). What I really
> measure is most of the time 3.24 µs (baudrate * 32?????) and sometimes
> 14.7 µs and seldom 17.7 µs. Any explanation?
> I then extended the testbuf to 7 bytes (0101010) and now I NEVER  see
> three equal pulses and space between them on my scope. Why do I have
> bitbang mode if it is like this??? Ok, I increased the baudrate to 65536
> (as suggested by Albert Huitsing) and now I see three equal spaced peaks
> and spaces very stable. If I increase the buffer to 9 bytes (011100010)
> I see most of the time a stable peak and space followed by a single peak
> but sometimes only a single peak. How can this all fit together?
> Sorry, I am a little bit lost here. Either I have totally misunderstood
> the whole thing or the FT232RL is just not made for this mode.

IIRC there was an issue with the first ftdi_write_data() call being
lost on application startup. So you could try to run your test patterns
in a loop with f.e. 5 seconds of pause in between. Does it look stable?

Also you could try to use libftdi-1 + libusb-1.x so test
if it makes any difference.


libftdi - see for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx

Current Thread