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,
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.
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?
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.