void iic_GPIO_Init(void)
{
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = SCL_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(SCL_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = SDA_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(SCL_GPIO_Port, &GPIO_InitStruct);
}
void SDA_OUT()
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = SDA_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(SDA_GPIO_Port, &GPIO_InitStruct);
}
void SDA_IN()
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = SDA_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed

本文档详细介绍了如何使用32位单片机模拟IIC通信协议,包括初始化GPIO、发送起始和停止信号、等待应答、发送和接收数据等关键步骤。此外,还提供了具体函数实现,如iic_start()、iic_stop()、iic_wait_ack()等,以及针对特定器件sy8801的读写操作函数。
最低0.47元/天 解锁文章
1083

被折叠的 条评论
为什么被折叠?



