title: using i2c in stm32l4r5
body: <p>I want use camera <code>ov5640</code> with <code>stm32l4r5 nucleo-144</code> kit. We use <code>i2c</code> for setting up camera. I am using following code for <code>i2c</code> communication.</p>
  
  <pre><code>#define OV5640_ADDR 0x78
  int ov7670_init(I2C_HandleTypeDef *p_hi2c)
  {
    sp_hi2c = p_hi2c;
    HAL_Delay(100);
    uint8_t reg;
    uint8_t buffer;
    reg = ov7670_read(OV5640_CHIPIDH, &amp;buffer);
    if (buffer == 0x56)
    {
        reg = ov7670_read(OV5640_CHIPIDL, &amp;buffer);
        if (buffer == 0x40)
        {
            return 0;
        }
        else
        {
            return 1;
        }
    }
    else
    {
        return 1;
    }
  }
  
  static int ov5640_write(uint16_t regAddr, uint8_t data)
  {
    HAL_StatusTypeDef ret;
    do {
          ret = HAL_I2C_Mem_Write(sp_hi2c, OV5640_ADDR, regAddr, I2C_MEMADD_SIZE_8BIT, &amp;data, 1, 100);
    } while (ret != HAL_OK &amp;&amp; 0);
    return ret;
  }
  
  
  static int ov7670_read(uint16_t regAddr, uint8_t *data)
  {
    HAL_StatusTypeDef ret;
    uint8_t regAddrMSB = regAddr &gt;&gt; 8;
    uint8_t regAddrLSB = regAddr &amp; 0x00FF;
    do {
      ret = HAL_I2C_Master_Transmit(sp_hi2c, OV5640_ADDR, &amp;regAddrMSB, 1, 100);
      ret |= HAL_I2C_Master_Transmit(sp_hi2c, OV5640_ADDR, &amp;regAddrLSB, 1, 100);
      ret |= HAL_I2C_Master_Receive(sp_hi2c, OV5640_ADDR, data, 1, 100);
    } while (ret != HAL_OK &amp;&amp; 0);
    return ret;
  }
  </code></pre>
  
  <p>I used <code>STM32CUBEMX</code> software for setting up <code>i2c</code> pins and generating related code for initialising <code>i2c</code> pins. The camera has <code>i2c</code> registers address is 16bit. But <code>i2c</code> communication not working. I am not able to read registers.</p>