F429 HAL库I2C驱动OV2640的问题

2019-07-20 19:46发布

设备ID一直读不出来怎么办,摄像头无应答
[mw_shl_code=c,true]void MX_I2C1_Init(void)
{
  hi2c1.Instance = I2C1;
  hi2c1.Init.ClockSpeed = 30000;
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
  hi2c1.Init.OwnAddress1 = 0xfd;
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
  hi2c1.Init.OwnAddress2 = 0xfe;
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
  HAL_I2C_Init(&hi2c1);
}

void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{

  GPIO_InitTypeDef GPIO_InitStruct;
  if(hi2c->Instance==I2C1)
  {
  
    /**I2C1 GPIO Configuration   
    PB6     ------> I2C1_SCL
    PB7     ------> I2C1_SDA
    */
    GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    /* Peripheral clock enable */
    __I2C1_CLK_ENABLE();
  }
}
} [/mw_shl_code]

[mw_shl_code=c,true]void OV2640_Read_ID()
{
        uint16_t reg;
        OV2640_IDTypeDef OV2640ID;
        if(OV2640_WriteReg(OV2640_DSP_RA_DLMT, 0x01) == HAL_OK){
                OV2640_ReadReg(OV2640_SENSOR_MIDH,&OV2640ID.Manufacturer_ID1);
                OV2640_ReadReg(OV2640_SENSOR_MIDL,&OV2640ID.Manufacturer_ID2);
                        reg=(OV2640ID.Manufacturer_ID1<<8)|OV2640ID.Manufacturer_ID2;
                        printf("MID:%04x",reg);
                OV2640_ReadReg(OV2640_SENSOR_PIDH,&OV2640ID.PIDH);
                OV2640_ReadReg(OV2640_SENSOR_PIDL,&OV2640ID.PIDL);
                        reg=(OV2640ID.PIDH<<8)|OV2640ID.PIDL;
                        printf("HID:%04x",reg);
        }
        else{
                printf("OV2640_WriteReg ERROR ");
                while(1);
        }
}

HAL_StatusTypeDef OV2640_WriteReg(uint16_t Addr, uint8_t Data)
{
  HAL_StatusTypeDef I2C_sta;
  //D′è&#235;&#188;&#196;′&#230;&#198;÷
  I2C_sta = HAL_I2C_Master_Transmit(&hi2c1,OV2640_DEVICE_WRITE_ADDRESS,&Data,1,DCMI_TIMEOUT_MAX);
  
        if(I2C_sta != HAL_OK)
        {
                I2C_Processing_Status(I2C_sta);
        }
        return I2C_sta;
}

HAL_StatusTypeDef OV2640_ReadReg(uint16_t Addr,uint8_t* data)
{
        HAL_StatusTypeDef I2C_sta;
        //·¢&#203;í&#188;&#196;′&#230;&#198;÷μ&#216;&#214;·
        I2C_sta = HAL_I2C_Master_Transmit(&hi2c1,OV2640_DEVICE_WRITE_ADDRESS,(uint8_t *)&(Addr),1,DCMI_TIMEOUT_MAX);
        //&#182;áè&#161;êy&#190;Y
        HAL_I2C_Master_Receive(&hi2c1,OV2640_DEVICE_READ_ADDRESS,data,1,DCMI_TIMEOUT_MAX);
        return I2C_sta;
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。