Not being able to retrieve data with I2C

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

cross mob
JoseRomo
Level 1
Level 1
First solution authored First like received First reply posted

Hello, I am experiencing some trouble when trying to get some data from an I2C port on Cy8CKit-059, I am trying to read 8 bytes through the port, everything in the code works well but the retrieved data is always 0. I checked on the protocol analyzer, and it seems that the data stops transmitting because of master nak's after the first read, even though I2C_MasterReadBuf is called with an 8 on the cnt parameter.

JoseRomo_0-1675927633038.png

 

the routine looks as follows (Ommiting the transmit part):

 

uint8_t ErrorCondition = I2C_MasterReadBuf(PortAdress, InputBuffer, BytesToRead, I2C_MODE_COMPLETE_XFER);

if(ErrorCondition){Return};

uint8_t status = I2C_MasterStatus();
while((status & (I2C_MSTAT_RD_CMPLT | I2C_MSTAT_ERR_XFER)) == 0u)
{
  status = I2C_MasterStatus();
}

if(status&I2C_MSTAT_RD_CMPLT){return I2C_Bus::ErrorConditions::Success;}
else{return I2C_Bus::ErrorConditions::UnknownError;}

 

 

After the execution of the previous code, InputBuffer contains only zeros

 

0 Likes
1 Solution
JoseRomo
Level 1
Level 1
First solution authored First like received First reply posted

I've solved it, the problem was somewhere else in the code, thanks for your help, the code above works as expected

View solution in original post

3 Replies
pacr_284376
Level 5
Level 5
100 replies posted 10 solutions authored 50 sign-ins

A word of advise (on any processor) when using I2C : Start with Presence detection of I2C devices. Check i2c adress range to confirm the correct slaves are detected. Mind that 50% of libraries (and datasheets) use 8-bit adress notation (0x10,0x12,0x14..0xFE) and the other 50% uses 7-bit adress notation (0x08, 0x09, 0x0A, 0x0B...0x7F). 8-bit 0x10 equals 7-bit 0x08. Make sure you understand the differences

When you get that working, you can continue sending real information to/from the slaves.

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

By any chance, can you download my sample below
https://community.infineon.com/t5/Code-Examples/MCU-Tester-a-Swiss-Army-Knife-for-PSoC-CY8CKIT-059-v...
and try i2c command such as "scan" and "read" ?

moto

JoseRomo
Level 1
Level 1
First solution authored First like received First reply posted

I've solved it, the problem was somewhere else in the code, thanks for your help, the code above works as expected