2 Replies Latest reply on Mar 26, 2012 10:07 AM by ali.ulucan

    UsbI2cRegMode Example Firmware Project

    ali.ulucan

      Hello,

      I want to read/write I2C EEPROM on the FX3 board with UsbI2cRegMode example firmware project.
      But I couldn't understand the process.

      Project readme file says,
      " The device enumerates as a vendor specific USB device with only the control endpoint and provides a set of vendor commands to read/write the data on I2C EEPROM devices.".

         

      That's all. There is no additional information how it can be realized.

      When I look over "CyFxUSBSetupCB" callback function and "CyFxUsbI2cTransfer" function,
       I can produce callback function's "setupdat0" and "setupdat1" parameters.

      1. How can I generate vendor commands with "setupdat0" and "setupdat1"?
      2. How can I send vendor commands within "USB Control Center"?
      3. When I send a read command, how can I observe the data?
      4. When I want to write to EEPROM, how can I send the EEPROM data?

      I would appreciate, if someone help me.

      Regards,
      Ali

        • 1. Re: UsbI2cRegMode Example Firmware Project
          laim.maskey

          Hi

             

                        

             

          In the USB Control Centre highlight the control endpoint, click on the data transfer tab and then enter values in the following fields to suit your application

             

          Direction                Out/IN you decide

             

          Req Type               Vendor

             

          Target                      Device

             

          Req Code              Your Vendor code

             

          wValue                    you decide

             

          wIndex                     you decide

             

          USB setup data is an 8 byte array sent by the host pc and these are stored in setupdat0 and setupdat1 which the firmware then parses to decode the control information contained in the setup data. In the eeprom example (cyfxusbi2cregmode.c) this is done in the following code

             

           /* Parse the control request parameters. */

             

              attr    =  (uint8_t) (setupdat0 & 0x000000FF);

             

              rqt     =  (uint8_t)((setupdat0 & 0x0000FF00) >> 8);

             

              value   = (uint16_t) (setupdat0 >> 16);

             

              index   = (uint16_t) (setupdat1 & 0x0000FFFF);

             

              length  = (uint16_t) (setupdat1 >> 16);

             

           

             

          attr is the request type and will be set by Control Centre when you select Vendor.

             

          rqt is the users vendor code and in this example for an eeprom read the code shows

             

           case CY_FX_RQT_I2C_EEPROM_READ:

             

                      i2cAddr = 0xA0 | ((value & 0x0007) << 1);

             

                      CyU3PMemSet (glEp0Buffer, 0, sizeof (glEp0Buffer));

             

                      status = CyFxUsbI2cTransfer (index, i2cAddr, length,

             

                              glEp0Buffer, CyTrue);

             

                      if (status == CY_U3P_SUCCESS)

             

                      {

             

                          status = CyU3PUsbSendEP0Data(length, glEp0Buffer);

             

                      }

             

                      break;

             

           

             

          If you look in cyfxusbi2cregmode.h you will see that this is defined as 0xBB

             

           Likewise the value field in this example is the eeproms address while index give the internal eeprom offset address.

             

           To read the eeprom then the following data is put into Control Centre

             

          Direction                 IN

             

          Req Type                 Vendor

             

          Target                      Device

             

          Req Code               0xBB

             

          wValue                    try 0x0000 but depends on how the eeprom address pins are set

             

          wIndex                     0x0000

             

           In the Bytes to Transfer Box type in the number of bytes you want to read.

             

          Hope this helps.

             

          Sodafarl

          • 2. Re: UsbI2cRegMode Example Firmware Project
            ali.ulucan

            Hi Sodafarl,

            Your answer was very clear and it worked. Thanks for your help.

            Regards,
            Ali