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

USB superspeed peripherals Forum Discussions

ArSa_3842301
Level 3
25 sign-ins 10 replies posted 10 questions asked
Level 3

Hi,
I am currently working in a CX3 project which need command an I2C device which has 1 byte address and 1 byte data.

To do that I have implemented a function based on standard function used to communicated with a Image sensor. But  changing the preamble structure in order to work correctly with the Data transfer format showed in slave device's data sheet (see the atached picture Data transfer).

*************************************************************************************************

CyU3PReturnStatus_t I2C_SendToSlave(uint8_t slaveAddr, uint8_t regAddr, uint8_t data)
{
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
CyU3PI2cPreamble_t preamble;

/* Customizacion del Preamble */
preamble.buffer[0] = slaveAddr;
preamble.buffer[1] = regAddr;
preamble.length = 2;
preamble.ctrlMask = 0x0000;

status = CyU3PI2cTransmitBytes(&preamble,&data,1,0);
CyU3PThreadSleep(1);
return(status);
}

*************************************************************************************************

Nevertheless CX3 is not able to command the I2C device. For this reason, I have capture the bus data in Oscilloscope. So, as you can see in the attached figure named i2c1byte CX3 only send the addres device (0x33) but does not send the address or the data. He send '1' all time instead.  Moreover, if I make a debug in firmware, it gives me an error code 0x55, and also 0x4A sometimes, when I call the CyU3PI2cTransmitBytes() function. 

So I have a couple of questions :

 - ¿Is I2C hard core embedded in CX3 able to send 1 byte address and 1 byte data? . If yes, how could I work properly with it?.

- ¿ Have I any issue in the function code? ¿Why I2C bus does not send the address or data?.

Thanks. 

0 Likes
1 Solution
JayakrishnaT_76
Moderator
Moderator First question asked 1000 replies posted 750 replies posted
Moderator

Hello,

I2C specification defines a 7 bit address for the slave devices. I think 0x33 found in the datasheet is this 7 bit slave address. Please find a snapshot of the data transfer which was shared by you in this thread before below:

JayakrishnaT_76_0-1633596669309.png

Here, slave address is 7 bit field. 0x33 found in the datasheet of I2C slave device will be this 7 bit field. After this 7 bit field, R/W bit should be inserted. This is required as per the I2C protocol. This is the reason why I asked you to change slaveAddr from 0x33 to 0x66. Please try this and let me know the results.

Best Regards,
Jayakrishna

View solution in original post

0 Likes
6 Replies
JayakrishnaT_76
Moderator
Moderator First question asked 1000 replies posted 750 replies posted
Moderator

Hello,

Firstly, the error codes that you see are described below:

0x4A - CY_U3P_ERROR_FAILURE - When a transfer fails with an error defined in CyU3PI2cError_t.

0x55 - CY_U3P_ERROR_LOST_ARBITRATION - Failure due to I2C arbitration error or invalid bus activity.

Please let us know if you are using a multi-master system. Also, if possible, kindly share a logic analyzer capture of the I2C traces.

In addition to this, in your description, you mentioned that the slave address is 0x33. Please let me know if you have added the R/W bit at the end of slaveAddr in the following line of code:

preamble.buffer[0] = slaveAddr;

As your slave address is 0x33, for a write operation, the value of slaveAddr should be 0x66. Please check if this is considered while writing the code.

Best Regards,
Jayakrishna
0 Likes
ArSa_3842301
Level 3
25 sign-ins 10 replies posted 10 questions asked
Level 3

I'm not using a multimaster system. In my design, CX3 is the single master, and has to command an image sensor and another I2C device which has only 1 byte data and 1 byte address , for this reason I have write another different function to transfer 1 byte address and data.

regarding with.. "you mentioned that the slave address is 0x33. Please let me know if you have added the R/W bit at the end of slaveAddr in the following line of code" : 

I have follow the example functions in the initial code example, so when I have to send a data to the slave device, I don´t have to add any mask R/W at the end of slaveAddr.  I guess I have to add the R/W bit at the end of slaveAddr only when I have to request a data from the device.

 

Regarding with "As your slave address is 0x33, for a write operation, the value of slaveAddr should be 0x66. Please check if this is considered while writing the code." 

Why  the slave addres shold be 0x66, if in datasheet is set in 0x33?. This device, only has one slave address for both write and read operations. 

 

Please could you share me the issues in the code? Thanks.

 

0 Likes
JayakrishnaT_76
Moderator
Moderator First question asked 1000 replies posted 750 replies posted
Moderator

Hello,

I2C specification defines a 7 bit address for the slave devices. I think 0x33 found in the datasheet is this 7 bit slave address. Please find a snapshot of the data transfer which was shared by you in this thread before below:

JayakrishnaT_76_0-1633596669309.png

Here, slave address is 7 bit field. 0x33 found in the datasheet of I2C slave device will be this 7 bit field. After this 7 bit field, R/W bit should be inserted. This is required as per the I2C protocol. This is the reason why I asked you to change slaveAddr from 0x33 to 0x66. Please try this and let me know the results.

Best Regards,
Jayakrishna
0 Likes
ArSa_3842301
Level 3
25 sign-ins 10 replies posted 10 questions asked
Level 3

I understand you now, I suppose that R/W bit was set automatically in I2C core.
I have change the device address to 0x66, but I continue having the same issue. You can see it in the attached image. But, for instance, it not happens if I set the slave address in 0x6C. In this case the send is correct, but the message is not have any effect in slave because of the addres slave is not correct.

How could I send the slave address 0x33 without having any issue, I mean, is there any form to set the value of the R/W, without having to include it into slave address value?

Thanks.

0 Likes
JayakrishnaT_76
Moderator
Moderator First question asked 1000 replies posted 750 replies posted
Moderator

Hello,

Can you please share the I2C traces captured using a logic analyzer? This can help us to understand the transfers between master and slave more easily.

When I referred to the snapshot shared in your previous response, I found that the slave did not send ACK after the master issued the slave address. Please cross check the behavior of the slave device.

Please refer to the snapshot below:

JayakrishnaT_76_0-1633604522626.png

This trace was captured at our end using the same code that was used at your end. The only difference is in the slave address as we were communicating with an EEPROM at our end.

Also, the first byte of preamble should contain the I2C address with the R/W bit included. There is no other way to specify the R/W bit.

Best Regards,
Jayakrishna
0 Likes
ArSa_3842301
Level 3
25 sign-ins 10 replies posted 10 questions asked
Level 3

Hi,
Thanks for your response, I have realized that the problem was coming from the Slave.

A part of that, It was necessary to adjust the I2C slave address to 0x66 in order to get a handshake between master and slave. So, it is already working properly.

Regards.

0 Likes