2 Replies Latest reply on Sep 5, 2017 6:23 AM by user_1377889

    PROC Blocking I2C

    dpelaezm_1818056

      Hello everyone.

       

      I am having an issue with the i2c functions when performing a read using the blocking functions. For some reason the first I2CMasterReadByte(0); is ignored and returns 0xE0.

      Below is the code to read 3 bytes from the eeprom, but it actually only reads 2. First, the address that you want to read is sent, then the read operation begins. Attached is an image from the logic analyzer.

       

          i2c_error = I2C_Master_I2CMasterSendStart(0b1010000,0);

          I2C_Master_I2CMasterWriteByte(0);   // address high byte

          I2C_Master_I2CMasterWriteByte(3);   // address low byte

          i2c_error = I2C_Master_I2CMasterSendStop();

          I2C_Master_I2CMasterSendStart(0b1010000,1);

          byte0 = I2C_Master_I2CMasterReadByte(0);

          byte1 = I2C_Master_I2CMasterReadByte(0);

          byte2 = I2C_Master_I2CMasterReadByte(1);

          i2c_error = I2C_Master_I2CMasterSendStop();

       

       

      To actually read 3 bytes I have to add an extra  I2CMasterReadByte(0), after the start function. Attached is also an image of the logic analyzer

       

          i2c_error = I2C_Master_I2CMasterSendStart(0b1010000,0);

          I2C_Master_I2CMasterWriteByte(0);   // address high byte

          I2C_Master_I2CMasterWriteByte(3);   // address low byte

          i2c_error = I2C_Master_I2CMasterSendStop();

          I2C_Master_I2CMasterSendStart(0b1010000,1);

          I2C_Master_I2CMasterReadByte(0);

          byte0 = I2C_Master_I2CMasterReadByte(0);

          byte1 = I2C_Master_I2CMasterReadByte(0);

          byte2 = I2C_Master_I2CMasterReadByte(1);

          i2c_error = I2C_Master_I2CMasterSendStop();

       

       

      Does anyone know why this behavior is occurring?