I2C_GenerateSTOP(I2C1, ENABLE); // Send STOP Condition
}
if(I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED)) // Test on EV7 and clear it
{
// Read bytes from the module
*pBuffer = I2C_ReceiveData(I2C1);
pBuffer++ ;
Num-- ;
}
}
I2C_AcknowledgeConfig(I2C1, ENABLE); // Enable Acknowledgement to be ready for another reception
}
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); //Test on EV5 and clear it
I2C_Send7bitAddress(I2C1, Module_ADDRESS, I2C_Direction_Transmitter); // Send module address for write
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); // Test on EV6 and clear it
for(i=0;i<Num;i++) // Send data
{
I2C_SendData(I2C1, *pBuffer); // Send the current byte
pBuffer++;
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); // Test on EV8 and clear it
}
I2C_GenerateSTOP(I2C1, ENABLE); // Send STOP condition
}