真的就不能直接用库函数的方式操作I2C吗,大家有用过的吗
void OV2640_HW_Init(void)
{
int i;
I2C_InitTypeDef I2C_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* SCL(PC6)¡¢SDA(PC7)1ü½ÅÅäÖà */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
for(i=0;i<10;i++){
GPIO_SetBits(GPIOB,GPIO_Pin_6);
delay_us(100);
GPIO_ResetBits(GPIOB,GPIO_Pin_6);
delay_us(100);
}
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure I2C1 */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
/* I2C DeInit */
I2C_DeInit(I2C1);
/* Set the I2C structure parameters */
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0xFE;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = 50000;
I2C_Cmd(I2C1, ENABLE);
/* Initialize the I2C peripheral w/ selected parameters */
I2C_Init(I2C1, &I2C_InitStructure);
/* Enable the I2C peripheral */
// I2C_Cmd(I2C1, ENABLE);
I2C_AcknowledgeConfig(I2C1,ENABLE);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
/* Initialize the I2C peripheral w/ selected parameters */
I2C_Cmd(I2C1, ENABLE);
上面的粘错了
一周热门 更多>