When I omit calling ftdi_set_bitmode function, writing works
flawlessly (reading as well). I am not sure if it is correct not to
set the bitmode by software; however, it seems that setting the "OPTO"
mode in EEPROM is sufficient.
Best regards,
Vojtech
On Thu, Apr 5, 2012 at 5:32 PM, Vojtech Michalek <vojtechuv@xxxxxxxxx> wrote:
>
> Hi all,
>
> I have an issue with Fast Opto-Isolated Serial Interface Mode on FT2232H.
> Reading from external device to PC works fine; however, writing does not work
> properly. The issue seems to lie in my code or libftdi, as it runs flawlessly
> while using proprietary linux drivers.
>
> While using libftdi I can only send 3600 bytes, then I got error -1 (usb bulk
> write failed). It seems that the data are jammed inside the FTDI chip and
> some buffer becomes full (when I purge buffers using ftdi_usb_purge_rx_buffer
> before reaching 3600 bytes, I can send another bytes to the chip). FSDO pin
> is persistenly at high level (there is no signal switching) and FSCTS is kept
> low (unlike when using proprietary drivers, in that case the FSCTS signal
> goes high after initial drop).
>
> Moreover, when I disconnect clock at FSCLK pin, also program using
> proprietary drivers jams after 3600 bytes are written.
>
> Here is the code I use:
>
>
> int main(int argc, char **argv)
> {
> struct ftdi_context ftdic;
> int f;
> unsigned long int sum;
> unsigned char buf[20];
> char* descstring="USB <-> Serial Cable";
> const char *errstr;
>
> if (ftdi_init(&ftdic) < 0)
> {
> fprintf(stderr, "ftdi_init failed\n");
> return EXIT_FAILURE;
> }
>
> if (ftdi_usb_open_desc(&ftdic, 0x0403, 0x6010, descstring, NULL) < 0)
> {
> fprintf(stderr,"Can't open ftdi device:
> %s\n",ftdi_get_error_string(&ftdic));
> return EXIT_FAILURE;
> }
> else
> fprintf(stderr,"Device opened\n");
>
> if (ftdi_set_interface(&ftdic, INTERFACE_A) < 0)
> {
> fprintf(stderr, "ftdi_set_interface failed\n");
> return EXIT_FAILURE;
> }
> fprintf(stderr,"Interface set\n");
>
> if(ftdi_set_latency_timer(&ftdic, 2))
> {
> fprintf(stderr,"Can't set latency, Error
> %s\n",ftdi_get_error_string(&ftdic));
> return EXIT_FAILURE;
> }
>
> //ftdi_usb_purge_rx_buffer(&ftdic);
> //ftdi_usb_purge_tx_buffer(&ftdic);
>
> if (ftdi_usb_purge_buffers(&ftdic) < 0)
> fprintf(stderr,"Purging buffers failed!\n");
> else
> fprintf(stderr,"Purging rx and tx buffers succeeded\n");
>
> f = ftdi_set_bitmode(&ftdic, 0x0, 0x10);
> if (f < 0) printf("Error while setting bitmode\n");
>
> f = ftdi_set_bitmode(&ftdic, 0x0, BITMODE_OPTO);
> //f = ftdi_set_bitmode(&ftdi, 0x0, 0x0);
> if (f < 0) printf("\n");
>
> printf("Writing...\n");
>
> buf[0]=0xAB;
> sum=0;
>
> while(1)
> {
> f = ftdi_write_data(&ftdic, buf, 20);
> errstr = strerror(errno);
> printf( "%s\n", errstr );
>
> if (f < 0)
> fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f,
> ftdi_get_error_string(&ftdic));
> else
> {
> sum+=f;
> fprintf(stderr,"%d byte(s) written successfully, %lu total\n",f,sum);
> fflush(stderr);
>
> //~ if (sum % 3500 == 0)
> //~ {
> //~ if (ftdi_usb_purge_rx_buffer(&ftdic)<0)
> //~ fprintf(stderr,"Rx buffer purge failed!\n");
> //~ else
> //~ fprintf(stderr,"Rx buffer purged\n");
> //~ }
> }
>
> fprintf(stderr,"RB offset: %u\n",ftdic.readbuffer_offset);
> fprintf(stderr,"RB remaining: %u\n",ftdic.readbuffer_remaining);
>
> usleep(100000);
> }
>
> ftdi_usb_close(&ftdic);
> ftdi_free(&ftdic);
>
> return 0;
> }
>
>
> Is there any obvious mistake?
>
> Have anyone successfully written to an external device using Fast
> Opto-Isolated Serial Interface Mode?
>
> Thanks,
> Vojtech
>
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|