void c02_write_data(void)
{
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
WRITE_FLAG=1;
I2C_GenerateSTART(I2C1, ENABLE);
// while(i2c_plan!=20);
//while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY));
//delay_ms(5);
}
void c02_read_data()
{
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
WRITE_FLAG=0;
STEP1=1;
STEP2=1;
I2C_GenerateSTART(I2C1, ENABLE);
}
/*********************************************zhongduan**********************/
void DebugMon_Handler(void)
{
}
/**
* @brief This function handles Debug Monitor exception.
* @param None
* @retval None
*/
void I2C1_EV_IRQHandler(void)
{
uint32_t lastevent= I2C_GetLastEvent(I2C1);
switch (lastevent)
{
case I2C_EVENT_MASTER_MODE_SELECT://EV5
if(WRITE_FLAG==1)
{
I2C_Send7bitAddress(I2C1, 0X50, I2C_Direction_Transmitter);
if((STEP1==1)&&(STEP2==1))
{
STEP1=0;
}
}
else
{
I2C_Send7bitAddress(I2C1, 0X50, I2C_Direction_Receiver);
STEP2=0;
}
break;
case I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED://EV6fa
if(WRITE_FLAG==1)
I2C_SendData(I2C1, WRITE_OFFSET);
else
I2C_SendData(I2C1, READ_OFFSET);
break;
case I2C_EVENT_MASTER_BYTE_TRANSMITTED://EV8
if(WRITE_FLAG==1)
{
I2C_SendData(I2C1, I2c_Buf_Write[WRITE_OFFSET]);
WRITE_OFFSET++;
if(WRITE_OFFSET!=0xff)
I2C_GenerateSTART(I2C1, ENABLE);
else
I2C_GenerateSTOP(I2C1, ENABLE);
}
else
{
I2C_GenerateSTOP(I2C1, ENABLE);
I2C_GenerateSTART(I2C1, ENABLE);
}
break;
case I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED://EV6SHOU
break;
case I2C_EVENT_MASTER_BYTE_RECEIVED://ev7
I2c_Buf_Read[READ_OFFSET] = I2C_ReceiveData(I2C1);
if(READ_OFFSET!=0xff)
I2C_GenerateSTART(I2C1, ENABLE);
else
I2C_GenerateSTOP(I2C1, ENABLE);
break;
}
}
本文来自论坛,点击查看完整帖子内容。