10 Replies Latest reply on Nov 9, 2018 1:27 AM by yumic_3247926

    FX3 I2C simple example



      is it possible that I can find somewhere a simple example how to utilize I2C in FX3? I need to write and read some data from external I2C sensor.


      I found example in SDK examples UsbI2cDmaMode and UsbI2cRegMode but as far as for now I don't really understand it.


      I have the following questions:


      1) How from PC do you write data to be later written via I2C?


      2) How later I use functions to read and write data via I2C? Do I have to create new thread?




      Thank you in advance for any support,





        • 1. Re: FX3 I2C simple example





          I2cregmode/i2cdmamode are the simplest examples available. I think you just need to familiarize yourself with Fx3 firmware flow.


          In the i2cregmode, there is a CyFxUsbI2cTransfer() function defined that performs the i2c read/write operations using the CyU3PI2cReceiveBytes() and CyU3PI2cTransmitBytes() API calls.


          And this functions is called inside the CyFxUSBSetupCB() function which is a callback function for USB EP0 commands.


          There are vendor requests defined for i2c read (CY_FX_RQT_I2C_EEPROM_READ) and write (CY_FX_RQT_I2C_EEPROM_WRITE). These vendor commands are recevied from the PC.




          You can call the CyFxUsbI2cTransfer() function from anywhere in the code based on your requirement.


          You can use the existing thread itself for your i2c read/write calls.





          • 2. Re: FX3 I2C simple example



            Thank you for the answer!


            Can you tell me how now I should write data from the PC? So that they are properly interpreted by FX3?







            • 3. Re: FX3 I2C simple example

              CY_FX_RQT_I2C_EEPROM_READ and CY_FX_RQT_I2C_EEPROM_WRITE are vendor commands sent out on EP0 from host to device.


              The Fx3 already has code to interpret them and take appropriate action (read/write to i2c). You can send these Ep0 requests from the Control Center application.





              • 4. Re: FX3 I2C simple example

                Are there any examples on how to send CY_FX_RQT_I2C_EEPROM_READ and CY_FX_RQT_I2C_EEPROM_WRITE from Linux?


                Is there a device driver which will do this, or is there a user space program on top of libusb which can do this?

                • 5. Re: FX3 I2C simple example

                  I appears that this can be done using libusb_control_transfer.


                  However, in my case it will timeout when the FX3 calls  CyU3PUsbSendEP0Data (I'm using CY_FX_RQT_ID_CHECK to read the glFirmwareID).

                  • 6. Re: FX3 I2C simple example

                    I also tried to use the cyusb_linux GUI program to send the CY_FX_RQT_ID_CHECK (0xB0) bRequest to return the glFirmwareID. But this is also failing:





                    • 7. Re: FX3 I2C simple example

                      Did anybody get this working on Windows?




                      I don't have a windows system, but I also get the same result with the pre-built firmware downloaded from:




                      The result using the Cypress GUI is the same as in the image above. I would have expected to read the firmware id, which I observe on the FX3 serial port:


                      =3A: Device initialized. Firmware ID: 20 33 58 46 0 43 32 49
                      =3B: Device initialized. Firmware ID: 20 33 58 46 0 43 32 49

                      • 8. Re: FX3 I2C simple example

                        Did anybody get this to work on any platform?


                        CyU3PUsbSendEP0Data will simply hang. Using CY_FX_RQT_I2C_EEPROM_READ CyFxUsbI2cTransfer will return CY_U3P_SUCCESS, but the following CyU3PUsbSendEP0Data will timeout.


                        Are there any chipsets which will not work with the FX3? I have tried both VIA and Intel and I get no data.

                        • 9. Re: FX3 I2C simple example

                          Please try by setting the bmRequest type to 0xC0  instead of 0x40 (SETUPDATA0 field in the above image)

                          • 10. Re: FX3 I2C simple example


                            What is Byte adress in CyFxUsbI2cTransfer() parameter


                            CyFxUsbI2cTransfer (

                                    uint16_t  byteAddress,

                                    uint8_t   devAddr,

                                    uint16_t  byteCount,

                                    uint8_t  *buffer,

                                    CyBool_t  isRead)

                            • 11. Re: FX3 I2C simple example


                              Did you solve the PC code?