模拟I2C控制24C02(3)
发布时间:2021-06-06
发布时间:2021-06-06
使用STM32红牛开发的GPIO模拟I2C控制八个AT24C02的读写
SCLL;
wait(10);
}
void GPIOC_Config_IN(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_MONII2C_SDA | RCC_APB2Periph_GPIOC , ENABLE);
/* moni SPI pins: SDA */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //输入上拉
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void GPIOC_Config_OUT(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_MONII2C_SDA | RCC_APB2Periph_GPIOC , ENABLE);
/* moni SPI pins: SDA */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; //开漏输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void I2C_EE_PageRead(u8* pBuffer, u16 ReadAddr, u16 NumByteToRead)
{
u16 i=0;
/* Send START condition */
I2C_GenerateSTART();
I2C_SendData(I2C_SLAVE_ADDRESS7_W);
//I2C_SLAVE_ADDRESS7=0xa0,伪写操作
WaitAck();
/* Send the EEPROM's internal address to write to */
I2C_SendData(ReadAddr);
WaitAck();
/* Send STRAT condition a second time */
I2C_GenerateSTART();
I2C_SendData(I2C_SLAVE_ADDRESS7_R);
//I2C_SLAVE_ADDRESS7=0xa1,读操作
上一篇:汽车火灾探测研究现状及发展趋势
下一篇:Android Widget