[tr]
STM32和pcf8591(a/d,d/a)通讯(按键控制),第一次按下去没问题,第二次就在这while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); 卡住了,求帮助一下
以下是按下按键后执行的函数:
/*******************************************************************************
* Function Name : u8 PCF8591_Read(void)
* Description : Receive data from channal 0 of PCF8591.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
u8 PCF8591_Read(void)//6
{
u8 temp;
/*----- Transmission Phase -----*/
printf("Generate Start I2C ...
");
/* Send I2C1 START condition */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on I2C1 EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); //第二次卡住的地方@@@@@@@@
printf("1...
");
/* Send PCF8591 slave Address for write */
I2C_Send7bitAddress(I2C1, 0x90, I2C_Direction_Transmitter);//Receiver
/* Test on I2C1 EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));// RECEIVER
printf("2...
");
/* Send data */
I2C_SendData(I2C1, 0x00);
/* Test on I2C1 EV8 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
printf("3...
");
/* Send I2C1 STOP Condition */
I2C_GenerateSTOP(I2C1, ENABLE);
printf("4...
");
/* Send I2C1 START condition */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on I2C1 EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
printf("5...
");
/* Send PCF8591 slave Address for read */
I2C_Send7bitAddress(I2C1, 0x91, I2C_Direction_Receiver);
/* Test on I2C1 EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
printf("6...
");
temp=I2C_ReceiveData(I2C1);
I2C_AcknowledgeConfig(I2C1, ENABLE);
I2C_GenerateSTOP(I2C1, ENABLE);
return temp;
}
[/tr]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>