FX2LP I2C does not work properly, EZUSB_WriteI2C does not return

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

cross mob
lock attach
Attachments are accessible only for community members.
docs_3756686
Level 2
Level 2
5 replies posted Welcome! 5 questions asked

Hello,

I am writing an FX2LP firmware, and I would like to read the battery voltage through I2C.

I implement my version based on I2C Read/Write in FX2LP - KBA224159  and https://www.cypress.com/documentation/application-notes/an45471-create-your-own-usb-vendor-commands-...

However it does not work, when I want to read via I2C.


I init the the I2C with the following code in the TD_init function:

EZUSB_InitI2C(); // Initialize I2C Bus

I2CTL |= 0x01; //400kHz

I2C communication code is in the getBatteryInfo() funciton:

BYTE xdata BUFFER[1];

BYTE xdata ee_str[1];

BYTE I2C_ADD = 0x6C;

ee_str[0] = 0x09;

EZUSB_WriteI2C(I2C_ADD, 1, ee_str);

EZUSB_ReadI2C(0x09, 0x01, BUFFER);

return BUFFER[0];

I tried to debug the code. I figured out that the EZUSB_WriteI2C function does not return, it stuck in the while loop. It seems that the I2CPckt.status hasnot got the good value.

I attached my code, please help, i have tried everthing.

Thanks,

Domi

0 Likes
1 Solution

Probably I found the problem.

Since getBatteryInfo() is called from ISR_Ep1out interrupt, I2C interrupt cannot interrupt ISR_Ep1out interrupt to send the data via I2C.

If I call getBatteryFunciton from TD_Poll, it works properly

View solution in original post

0 Likes
4 Replies
Sananya_14
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hello Domi,

-For the read operation, the I2C slave address passed in EZUSB_ReadI2C() should be that of the slave device and not the internal register address.

-Could you kindly attach a capture showing the I2C bus lines when getBatteryInfo() function is called? This will confirm the I2CPckt.status value since the EZUSB_WriteI2C() function checks for each of those values in the while loop and sets the return value accordingly.

Best Regards,

Sananya

0 Likes

Hello,

thanks for you answer.
1. yes it is a mistake, however it does not reach that line of code, becasue if i delete this line, it still does not return the EZUSB_WriteI2C function.
2.

the  image is attached (sorry for the bad quality). I see that the clcok signal stay in 0. What could be the problem?

NewFile1.png

I attached the I2C protocol of the slave:pastedImage_0.png

It looks like the ACK is recevied from the slave, however the cypress does not send the data (regist. address) to the slave. It looks like the interrupt does not work and does not send the data to slave. What could be the problem? How should I set up the I2C interrupt? OR what is the problem?

Thanks for you help,

Domi

0 Likes

Probably I found the problem.

Since getBatteryInfo() is called from ISR_Ep1out interrupt, I2C interrupt cannot interrupt ISR_Ep1out interrupt to send the data via I2C.

If I call getBatteryFunciton from TD_Poll, it works properly

0 Likes
lock attach
Attachments are accessible only for community members.

I was, in the past, forced to modify the source code of the EZUSB lib.

The code "void i2c_isr (void) interrupt I2C_VECT" did not contain a default case.

I introduced a general error and changed the functions EZUSB_ReadI2C and EZUSB_WriteI2C.

If that can help you...

0 Likes