Cannot set GPIO pins in FT230X in Centos

747 views Asked by At

I have LEDs connected to CBx pins of FT230X. I am using libftdi v1.2 to set FT230X CBx pins. I am tried both 2 bitbang modes: BITMODE_BITBANG and BITMODE_CBUS, but without any result. My code is somewhere about follow:

#include <ftdi.h>
#include <err.h>
int main(int argc, char *argv[])
{
  struct ftdi_context ftdi;
  unsigned char x;

  /* Initialize and find device */
  if (ftdi_init(&ftdi) < 0)
    err(1, "ftdi_init");

  if (ftdi_usb_open(&ftdi, 0x0403, 0x6015) < 0)
    err(2, "can't open device");

  /* Enable bitbang */
  if (ftdi_set_bitmode(&ftdi, 0xff, BITMODE_BITBANG) < 0)
    err(3, "can't enable bitbang mode");

  /* Write Yellow */
  x=0x00;
  if (ftdi_write_data(&ftdi, &x, 1) < 0)
    err(5, "can't write");
  sleep(3);
  /* Write Red */
  x=0x01;
  if (ftdi_write_data(&ftdi, &x, 1) < 0)
    err(5, "can't write");
  sleep(3);
  /* Write Green */
  x=0x02;
  if (ftdi_write_data(&ftdi, &x, 1) < 0)
    err(5, "can't write");
  sleep(3);

  /* Close device */
  ftdi_usb_close(&ftdi);
  ftdi_deinit(&ftdi);

  return 0;
}

It should be noted that the same code (exclude product id = 0x6013) works properly for FT4232H.

1

There are 1 answers

0
Yakovs On

I resolved my problem. As I mentioned, I need to set CBx pins on FT230X. For this case in the FT230X should be enabled BITMODE_CBUS mode in EEPROM. In BITMODE_CBUS mode, as it described in bitbang_cbus.c example of libftdi, to set these CBx pins should be used only ftdi_set_bitmode() function. Wherein in the second parameter (bitmask) the top nibble controls input/output and the bottom nibble controls the state of the lines set to output.