CX3, i2c , 2-bytes address, 2-bytes data

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

cross mob
AkCh_1378701
Level 3
Level 3
First like given

Hi sir,

i encounter an issue of accessing a image sensor via i2c.. might need a recommendation for properly debugging..

The register of the sensor has 2 bytes address , and 2 byte value, the slave address is 0x20..

basically, the sensor indeed returns ACK, right after sending slave address (0x20), there  is no i2c slave address conflict.

i wanna read 2 bytes data from 2 bytes register, which has 0x3000 address..

when i send a i2c read commands,  the sensor seems never returnning ACK after 0x21 (read command), attaching the i2c waveform below.

IMG_3461.jpg

the i2c waveform above after decode as below.

20 30 00 21#

S: Start signal

# -> NAK

the sensor never returns the data, but NACK..

error code returned is

ImageSensorSensorRead Failed addr=0x3000, status = 0x4A

the actual code being sent as below ..

    for(cnt=0; cnt<3 ; cnt++)   //

    {

        preamble.buffer[1] = CY_U3P_GET_MSB (regAddr);

        preamble.buffer[2] = CY_U3P_GET_LSB (regAddr);

        preamble.buffer[3] = SENSOR_I2C_READ_ADDRESS; /* Slave address: Read operation */

        preamble.buffer[0] = SENSOR_I2C_WRITE_ADDRESS; /* Slave address: write operation */

        preamble.length = 4;

        preamble.ctrlMask = 0x0004;

        status = CyU3PI2cReceiveBytes (&preamble, buf, count,0);

        SensorI2CAccessDelay(status);

        CyU3PThreadSleep(1);

        if (status == CY_U3P_SUCCESS)

        {

            break;

        }

#ifdef SENSOR_DEBUG

        else

            CyU3PDebugPrint(4,"\r\nImageSensorSensorRead Failed addr=0x%x, status = 0x%x",regAddr, status);

#endif

    }

    return status;

thank you

0 Likes
1 Solution

We don't need specific caution on CX3 I2C part. The values of 2.2k/4.7k which are commonly used should work.

View solution in original post

0 Likes
7 Replies
abhinavg_21
Moderator
Moderator
Moderator
50 likes received 25 likes received 10 likes received

Hi,

Could you please provide some detail about SensorI2CAccessDelay() function. Please check error status immediately after CyU3PI2cReceiveBytes(). I assume that the SENSOR_I2C_READ_ADDRESS & SENSOR_I2C_WRITE_ADDRESS are in the I2C spec.

Bit 7 - 1: Slave address.

Bit 0    : 0 - Indicating this is a write/read from master.

If not please confirm.

Thanks & Regards

Abhinav

0 Likes

over here.

static void SensorI2CAccessDelay( CyU3PReturnStatus_t status)

{

    //

    // Add a 10us delay if the I2C operation that preceded this call was successful.

    //

    if (status == CY_U3P_SUCCESS)

         CyU3PBusyWait(10);

}

0 Likes
YangyangC_06
Employee
Employee
750 replies posted 500 replies posted 250 replies posted

Hi Akeem,

-Which sensor are you going to interface with CX3? Please kindly check the hardware design according to the application note/datasheet from sensor vendor.

-Please check if the sensor is well initialized(reset and power) and if it is ready for receiving data from I2C port. Generally speaking, sensors will not ACK I2C command if it is not well intialized.

-Please check if you set the correct W/R slave address in firmware. It is common that a sensor has two or more I2C address according to different connection condition.

-It is strange that the amplitude of SCL/SDA drops from your screenshot. Check if anything abnormal on your I2C hardware part.

- I recommend you capture the I2C communication with logic analyzer. It is easy to check what happened on I2C port.

- Do you modify the definition of SensorI2CAccessDelay? Try to print the error code.

0 Likes

thanks for the recommendation,

i think it could likely issue of value of i2c pull up... looks like that CX3 doesn't have internal pull for SDA and SCL. so i have to wire them externally.

Does CX3 have a recommendation for specific value of pull up resistor?

0 Likes

We don't need specific caution on CX3 I2C part. The values of 2.2k/4.7k which are commonly used should work.

0 Likes

Thanks.

the issue was resolved by proper value of pull-up resistor.

0 Likes

Congratulations to you. I will close this ticket later.

0 Likes