Reading MT9MD131 i2c sensor from FX3

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

cross mob
Anonymous
Not applicable

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.

0 Likes
2 Replies
Anonymous
Not applicable

Hi,

   

"ctrlMask" field of the preamble controls the start stop condition after every byte of preamble data.

   

In the case of MT9M114,since address size is 16 bits  and preamble length =4, ctrlMask field is set to 0x0004, to indicate that a start bit is required after third byte of the preamble.

   

But, in the case of MT9M131 sensor, since the address size is 8 bits and preamble length=3, ctrlMask field should be set to 0x0002 to indicate that a start bit is required after second byte of the preamble.

   

So, you need to set the preamble.ctrlMask  = 0x0002  

0 Likes
Anonymous
Not applicable

ok thanks.

   

It works fine.

0 Likes