Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

USB interface adapter control using python

Other Parts Discussed in Thread: TCA6424A

Hi, 

Can we control the TI's USB Interface Adapter using python??

I need to toggle the GPIO pins to control the LEDs.

Kindly suggest me on this.

Thanks and regards,

Vishal

  • Hi Vishal,

    Which TI device you are using?

    Do you use Linux, RTOS or else?

    Regards,
    Pavel

  • Hi Pavel,

    I have the adapter with me. As it has GPIO pins, need to control them using Python.

    I'm using Windows OS.

    Regards,

    Vishal

     

  • Hi Vishal

    This looks like a very old product and unfortunately we do not have any further guidance or collateral to provide on this.

    Regards

    Mukul 

  • Hi Vishal

    I found that this specific product is owned by another product group, so I have reassigned this query to that team, in case they have more guidance.

    Hope this helps.

    Regards

    Mukul 

  • Hi Mukul,

    It should be possible since I believe that particular adapter makes use of the standard USB HID (Human Interface Device) driver which could be controlled by any software (and there should be readily-available Python code to interface with these types of USB devices).  I'm not sure I could guide you any further with specifics, though, since I have not personally done this and it is a bit outside the scope of what that interface adapter is intended for.

    Regards,
    Max

  • Thanks Max.

    I shall check on those drivers.

    Regards,

    Vishal

  • Hi Mukul,

    Thanks for the support.

    Do let me know the info of the product driver's which are relevant for it to be programmed using python.

    Regards,

    Vishal

  • Hi Vishal

    I would just go with the recommendation Max provided. I do not have further guidance on this. 

    Regards

    Mukul 

  • Hi Vishal,

    I will add some additional information that might clarify how to control the USB-to-GPIO adapter using Python. 

    It uses the TUSB3210 USB MCU and is programmed to appear as a HID device.  The architecture is pretty straight forward and it is essentially a big state machine waiting for an incoming USB packet from the PC which consists of a 64 byte data payload.  Byte 0 of the data payload is the state machine's command byte or Op Code.  When the USB packet is received into the MCU's input buffer, the MCU reads byte 0 and executes the code associated with that byte in the state machine.  Then the MCU will place a response packet into the Output buffer for transmission the next time the PC requests data from the USB HID device. 

    The USB-to-GPIO datasheet contains the packet byte info for the various functions programmed into the MCU as well as the response packets.  The subsequent data bytes in the 64 byte packet are function specific information

    For example, the an I2C Write operation, the Command Code or Byte 0 of the packet is 0x14.  The I2C Read operation Command Byte or Byte 0 is 0x15.  If you wanted to write to a TCA6424A device register through I2C, you might have a USB packet such as {0x14, 0x22, 0x04, 0x01, 0x55, <0x00...0x00>}.

    0x14 is the I2C Write function, 0x22 is the device Slave Address, 0x04 is the Register Address, 0x01 is the number of bytes to write which is 1 in this case, and 0x55 is the value to write into the register.  The rest of the 64 byte packet is don't care since you told the MCU to only write 1 byte.  I usually padded that with 0's, but it can be whatever you want.

    Once you write this USB packet, then you should check for a response packet from the MCU with the USB data payload byte 0 of 0x94.  This is unique to the I2C write response.  Then byte 1 will be either 0x00, or 0x01 to indicate success (0) or fail (1).

    I have not ever used the GPIO pins, but I believe the command code (byte 0) for setting those is 0x16 with a response packet Command Byte of 0x96.  Details can be found in the datasheet.

    I have used the pywinusb module in Python 2.7 which has lots of online documentation and examples you can reference.

    You should verify the Vendor ID (VID) and Product ID (PID) values through the PC's hardware manager, but I believe the VID = 0x0451, and the PID = 0x5F00.  In Python you will need to initialize a device handle.  Then create an output report to store the status info from the PC about the success/failure of your USB packets.  Then create a buffer for your data packets which you will load up per the state machine function information found in the USB-to-GPIO datasheet.  The Report ID buffer needs to be be appended to the front of the data buffer when it is sent.  However, it is not seen by the MCU and byte 0 of the MCU's input buffer will be your command byte as I have shown below from some old sample code of mine.  An example buffer for an I2C write command might look like the following.

    buffer = [0x00]*65                       #65 = report size + 1 byte (report id)
    buffer[0] = 0x00                           #report id
    buffer[1] = 0x14                           #I2C Write Command Op Code
    buffer[2] = devAddress * 2        #Slave Address shifted by 1 bit + write bit of 0
    buffer[3] = regAddress              #Register Address Byte (command byte)
    buffer[4] = 0x01                           #Number of bytes to write
    buffer[5] = regData                     #Byte to write (Register Value)

    If you are still trying to get your communication setup and running, I hope this extra information helps.  I would suggest looking at the Python modules for USB HID communication such as the pywinusb module.  Then follow the documentation and example code available to setup your unique functions that will create your data buffer as needed. 

    Regards,

    Jonathan