4 Replies Latest reply on May 19, 2019 11:20 PM by KandlaguntaR_36

    i2c long reigster address read/write

    xingxingg_1705831

      hi
           CyU3PI2cPreamble_t works well if the i2c address is only 2-4 bytes width. but if the register address width is longer than 8 bytes, it is hard to use this structure.
          who know how configure CyU3PI2cPreamble_t if the register length longer then 8 bytes.
      for example, if i want to read register address 0x123456789acbde1234,  the value with is 10byes, how to configure?

       

       

      i tried to separate write/read sequence using following two functions. but cannot work seems due to clock-stretching. who can help here?

       

       

       

      CyU3PReturnStatus_t

      GW5200_SensorReadNB(uint8_t SlaveAddr, uint8_t *buf, int n)

      {

          CyU3PReturnStatus_t apiRetStatus=CY_U3P_SUCCESS;

          CyU3PI2cPreamble_t preamble;

          int i = 0;

       

       

        preamble.buffer[0] = SlaveAddr;//0x21;

        preamble.length = 1;

        preamble.ctrlMask = 0x0000;//After the second byte,need to restart the I2C communication

        apiRetStatus = CyU3PI2cReceiveBytes (&preamble, buf, n,0);

        if (apiRetStatus == CY_U3P_SUCCESS)

        {

        IMX390_GW_delay(800);

        }

        else

        CyU3PDebugPrint (4, "GW5200_SensorReadNB failed Error Code = %d\n",apiRetStatus);

      #if 1

        CyU3PDebugPrint (4, "read:");

        for(i = 0; i < n; i++)

        {

        CyU3PDebugPrint (4, "0x%x ", buf[i]);

        }

        CyU3PDebugPrint (4, "\r\n");

      #endif

       

        return apiRetStatus;

      }

       

       

      CyU3PReturnStatus_t

      GW5200_SensorWriteNB(uint8_t SlaveAddr,uint16_t count, uint8_t *buf)

      {

          CyU3PReturnStatus_t apiRetStatus=CY_U3P_SUCCESS;

          CyU3PI2cPreamble_t preamble;

          int i = 0;

       

        preamble.buffer[0] = SlaveAddr; /* Slave address: Write operation */

        preamble.length = 1;

        preamble.ctrlMask = 0x0000;

        apiRetStatus = CyU3PI2cTransmitBytes (&preamble, buf, count, 0);

        if (apiRetStatus == CY_U3P_SUCCESS)

        {

        IMX390_GW_delay(800); /* known issue for SDK I2C */

        }

        else

        {

        CyU3PDebugPrint (4, "GW5200_SensorWriteNB error!\r\n");

        }

      #if 0

        CyU3PDebugPrint (4, "write:");

        for(i = 0; i < count; i++)

        {

        CyU3PDebugPrint (4, "0x%x ", buf[i]);

        }

        CyU3PDebugPrint (4, "\r\n");

      #endif

        return apiRetStatus;

      }

       

       

      thanks
      xingxing