2 Replies Latest reply on Nov 21, 2016 2:01 AM by oscargomezf_2018731

    Reading MT9MD131 i2c sensor from FX3

    oscargomezf_2018731

      Hi everyone,

         

       

         

      I'm trying to read the i2c registers from MT9M131 CMOS sensor using the FX3 IC. I was reading the UVC_AN75779 example. But this CMOS sensor: MT9M131 is slightly different from MT9M114 used in the example UVC_AN75779:

         

      The address size is 8 bits instead of 16 bits, so I have to change the functions SensorRead2B and SensorWrite2B.

         

      I've started changing the fucntion SensorRead2B, but it doesn't work, so I'm not sure If I doing this issue correctly. According to the datasheet of the MT9M131, this is the scheme of a reading of 16 Bits:

         

      START - Address (0xBA) - ACK - Address2read (For example: 0x02) - ACK - START - Address (0xBB) - ACK - Data MSB  (8 bits) - ACK - Data LSB  (8 bits) - NACK - STOP 

         

      And this is the function I can't achieve to work well:

         

      CyU3PReturnStatus_t SensorRead2B (
              uint8_t slaveAddr,
              uint8_t addr,
              uint8_t *buf)
      {
          CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
          CyU3PI2cPreamble_t preamble;

         

          if ((slaveAddr != SENSOR_ADDR_RD) && (slaveAddr != I2C_MEMORY_ADDR_RD))
          {
              CyU3PDebugPrint (4, "I2C Slave address is not valid!\r\n");
              return 1;
          }

         

          preamble.buffer[0] = slaveAddr & I2C_SLAVEADDR_MASK;        /*  Mask out the transfer type bit. */
          preamble.buffer[1] = addr;
          preamble.buffer[2] = slaveAddr;
          preamble.length    = 3;
          preamble.ctrlMask  = 0x0004;                                /*  Send start bit after second byte of preamble. */
       

         

          apiRetStatus = CyU3PI2cReceiveBytes (&preamble, buf, 2, 0);
          SensorI2CAccessDelay (apiRetStatus);

         

          return apiRetStatus;
      }

         

      Any suggestion?

         

       

         

      Best regards.