use GPIO to simulate I2C

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 hi, all

   

I want to use GPIO to simulate I2C, as we all know, SDA is bidirectional IO. How can i configure this GPIO?

   

 

   

Best Regards,

   

Junior

0 Likes
6 Replies
Anonymous
Not applicable

 additionally, I using CYUSB3014.

0 Likes
Anonymous
Not applicable

 Hi TwinBoy,

   

 

   

Please check the I2C GPIO example in the firmware examples folder in the sdk installed location.

   

 

   

Thanks,

   

Gokul Prasath N

0 Likes
Anonymous
Not applicable

 Hi, Gokul 

   

Thanks for reply. I know those examples in SDK installed folder. Those examples use FX3API to configure I2C. I don't want to use this API to configure I2C. I want to use GPIO 50 and GPIO 51 to simulate I2C and write all I2C functions myself.SDA is bidirectional IO. How can i configure this GPIO? The following code is configure of SCL, which is unidirectional. outValue is true and inputEn is false. How to configure SDA? This GPIO is bidirectional.

   

/*Configure GPIO 50 as output(I2C_CLOCK). */
gpioConfig.outValue       = CyTrue;
gpioConfig.inputEn         = CyFalse;
gpioConfig.driveLowEn  = CyTrue;
gpioConfig.driveHighEn = CyTrue;
gpioConfig.intrMode      = CY_U3P_GPIO_NO_INTR;

apiRetStatus = CyU3PGpioSetSimpleConfig(FX3_I2C_CLK, &gpioConfig);

   

 

   

Best Regards,

   

 

   

Junior

0 Likes
Anonymous
Not applicable

 Hi ,

   

 

   

I dont think cypress allows both input and output are configured to a same GPIO pin. It is recommended not to use. You may try like having two sda pins one for i/p and other for o/p(May work).

   

 

   

Thanks

0 Likes
Anonymous
Not applicable

Hi,

According I2C specification, both SDA and SCL are actually open-drain bidirectional lines.

gpioConfig.inputEn=CyTrue; //read signal value from pin (not from output register)
gpioConfig.driveLowEn=CyTrue; //if output value=0 then drive this value to pin, i.e. pull pin low
gpioConfig.driveHighEn=CyFalse; //if output value=1 then do not drive this value to pin, i.e. tri-state pin

br,
Kalev
 

0 Likes
Anonymous
Not applicable

Hi, Gokul and Kalev

   

Thanks for replies and suggestions.

   

 

   

Best Regards,

   

Junior

0 Likes