中级会员
- 积分
- 278
- 威望
- 194
- 贡献
- 74
- 兑换币
- 0
- 注册时间
- 2011-5-4
- 在线时间
- 5 小时
|
通过I2C对C3088的寄存器进行配置,读设备地址为0xc0,写地址为0xc1,现在得不到我想要的结果,我想看看寄存器配置成功没有就写了个通过I2C读寄存器的函数,当我调用读寄存器的函数时就检测不到总线空闲的标志,一直处于忙的状态,不知道是怎么回事
代码如下:
void I2C_Configuration(void)
{
I2C_InitTypeDef I2C_InitStructure;
I2C_Cmd(I2C1, ENABLE);
/* I2C1 Init */
//===========================
I2C_DeInit(I2C1);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; //设置I2C为I2C模式
//===========================
//I2C_InitStructure.I2C_Mode = I2C_Mode_SMBusHost;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0x00;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; //有应答的通信
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = 100000;
I2C_Init(I2C1, &I2C_InitStructure);
//===============================
/*允许1字节1应答模式*/
I2C_AcknowledgeConfig(I2C1, ENABLE);
//===============================
}
void I2C_C3088_ConfReg_Write(u8 Reg_Addr,u8 RegValue)
{
/*----- Transmission Phase -----*/
while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)!=RESET); //只有BUSY = 0 时, 可以发送开始位
/* Send I2C1 START condition */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on I2C1 EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) /* EV5 */
{
}
/* Send C3088 slave address for write */
I2C_Send7bitAddress(I2C1, C3088_Addr, I2C_Direction_Transmitter);
/* Test on I2C1 EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */
{
}
/* Send the configuration register data pointer */
I2C_SendData(I2C1, Reg_Addr);
/* Test on I2C1 EV8 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
{
}
/* Send I2C1 data */
I2C_SendData(I2C1, RegValue);
/* Test on I2C1 EV8 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
{
}
/* Send I2C1 STOP Condition */
I2C_GenerateSTOP(I2C1, ENABLE);
}
u8 I2C_C3088_ConfReg_Read(u8 Reg_Addr)
{
u8 RegValue = 0;
/*----- Transmission Phase -----*/
while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)!=RESET); //只有BUSY = 0 时, 可以发送开始位
//=================================
/*允许1字节1应答模式*/
I2C_AcknowledgeConfig(I2C1, ENABLE);
//==============================
/* Send I2C1 START condition */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on I2C1 EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) /* EV5 */
{
}
//===========================
/* Send c3088 read address for write */
I2C_Send7bitAddress(I2C1, C3088_Addr, I2C_Direction_Transmitter);
//===========================
/* Test on I2C1 EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */
{
}
/* Send the configuration register data pointer */
I2C_SendData(I2C1, Reg_Addr);
/* Test on I2C1 EV8 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
{
}
/*----- Reception Phase -----*/
//while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)!=RESET); //只有BUSY = 0 时, 可以发送开始位
/* Send Re-STRAT condition */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) /* EV5 */
{
}
/* Send STLM75 slave address for read */
I2C_Send7bitAddress(I2C1, C3088_Addr_read, I2C_Direction_Receiver);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) /* EV6 */
{
}
/* Disable I2C1 acknowledgement */
I2C_AcknowledgeConfig(I2C1, DISABLE);
/* Send I2C1 STOP Condition */
I2C_GenerateSTOP(I2C1, ENABLE);
/* Test on EV7 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED)) /* EV7 */
{
}
/* Store I2C1 received data */
RegValue = I2C_ReceiveData(I2C1);
//=================================
I2C_AcknowledgeConfig(I2C1, ENABLE);
//=================================
/* Return configuration register value */
return (RegValue);
} |
|