设备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′èë¼Ä′æÆ÷
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;
//·¢Ëí¼Ä′æÆ÷μØÖ·
I2C_sta = HAL_I2C_Master_Transmit(&hi2c1,OV2640_DEVICE_WRITE_ADDRESS,(uint8_t *)&(Addr),1,DCMI_TIMEOUT_MAX);
//¶áè¡êy¾Y
HAL_I2C_Master_Receive(&hi2c1,OV2640_DEVICE_READ_ADDRESS,data,1,DCMI_TIMEOUT_MAX);
return I2C_sta;
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>