void I2C1_EV_IRQHandler(void)
{
switch(I2C_GetLastEvent(I2C1))
{
case I2C_EVENT_MASTER_MODE_SELECT:
{
I2C_Send7bitAddress(I2C1,I2C2_SLAVE_ADDRESS7,I2C_Direction_Transmitter);
break;
}
case I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED:
{
I2C1_Buffer_Rx[Rx_Idx++]=I2C_ReceiveData(I2C1);
printf("%d",I2C1_Buffer_Rx[Rx_Idx-1]);
break;
}
case I2C_EVENT_MASTER_BYTE_RECEIVED:
{
if(Tx_Idx<Buffersize)
{
I2C1_Buffer_Rx[Rx_Idx++]=I2C_ReceiveData(I2C1);
printf("%d",I2C1_Buffer_Rx[Rx_Idx-1]);
}
else
{
I2C_GenerateSTOP(I2C1,ENABLE);
I2C_ITConfig(I2C1,I2C_IT_EVT | I2C_IT_BUF, DISABLE);
}
break;
}
default: break;
}
}
void I2C2_EV_IRQHandler(void)
{
switch(I2C_GetLastEvent(I2C2))
{
case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED:break;
case I2C_EVENT_SLAVE_BYTE_TRANSMITTED:
{
if(Tx_Idx<Buffersize)
{
I2C_SendData(I2C2,I2C2_Buffer_Tx[Tx_Idx++]);
}
break;
}
case I2C_EVENT_SLAVE_STOP_DETECTED:
{
I2C_ClearFlag(I2C2,I2C_FLAG_STOPF);
I2C_ITConfig(I2C2,I2C_IT_EVT | I2C_IT_BUF, DISABLE);
break;
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>