新手入门
- 积分
- 6
- 金钱
- 6
- 注册时间
- 2020-12-1
- 在线时间
- 1 小时
|
各位大佬,想配置一个硬件IIC 用来做从机,查了各种平台的参考之后,一直无效,想请教一下,这个配置是还缺少什么嘛?
平台用的STM32F103zet6
void iic_gpio_init()
{
GPIO_InitTypeDef GPIO_InitStruct; //¶¨òåIIC1μÄGPIO½á11ìå±äá¿
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB ,ENABLE); //ê1ÄüGPIOμÄê±Öó
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; //¸′óÿa©êä3ö£¬ ¿ÕÏDê±±»éÏà-μç×èà-3é¸ßμçƽ
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
}
void IIC_Init(void)
{
I2C_InitTypeDef I2C_InitStruct;
NVIC_InitTypeDef NVIC_InitStructure;//nvicÅäÖÃ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //ê1Äü¸′óÃê±Öó
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
//GPIO¸′óÃIIC1
GPIO_PinRemapConfig(GPIO_Remap_I2C1,ENABLE);
I2C_DeInit(I2C1);
I2C_InitStruct.I2C_ClockSpeed = 100000; //éèÖÃê±ÖóËù¶è 100k
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; //éèÖÃiICÄ£ê½ÔËDD
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; //éèÖÃÑ°Ö·
I2C_InitStruct.I2C_OwnAddress1 = 0x5A; //éèÖÃμØÖ·
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2; //éèÖÃÕ¼¿Õ±è£
I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
I2C_Init(I2C1,&I2C_InitStruct);
I2C_Cmd(I2C1, ENABLE);
I2C_AcknowledgeConfig(I2C1,ENABLE);
}
|
|