金牌会员
- 积分
- 1897
- 金钱
- 1897
- 注册时间
- 2016-8-20
- 在线时间
- 238 小时
|
楼主 |
发表于 2018-8-24 08:30:48
|
显示全部楼层
[mw_shl_code=applescript,true]void IIC_Write(unsigned char addr,unsigned char data)
{
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)); //等待空闲
I2C_GenerateSTART(I2C1, ENABLE);//开启I2C1
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));/*EV5,主模式*/
I2C_Send7bitAddress(I2C1, I2C1_WRITE_ADDRESS7, I2C_Direction_Transmitter);//器件地址 -- 默认0x90
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(I2C1, addr);//寄存器地址
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_SendData(I2C1, data);//发送数据
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_AcknowledgeConfig(I2C1,ENABLE);
I2C_GenerateSTOP(I2C1, ENABLE);//关闭I2C1总线
}[/mw_shl_code] |
|