/* Sends data and read data in master mode through the I2Cx peripheral.  */
void I2C_MasterRepeatRead(I2C_TypeDef *I2Cx, u8 *pWriteBuf, u8 Writelen, u8 *pReadBuf, u8 Readlen)
/* Sends data and read data in master mode through the I2Cx peripheral.  */
void I2C_MasterRepeatRead(I2C_TypeDef *I2Cx, u8 *pWriteBuf, u8 Writelen, u8 *pReadBuf, u8 Readlen)
{
	u8 cnt = 0;
	assert_param(IS_I2C_ALL_PERIPH(I2Cx));
	for(cnt = 0; cnt < Writelen; cnt++)
	{
		while((I2C_CheckFlagState(I2Cx, BIT_IC_STATUS_TFNF)) == 0);
		if(cnt >= Writelen - 1)
		{
			I2Cx->IC_DATA_CMD = (*pWriteBuf++) | (1 << 10);
		}
		else
		{
			I2Cx->IC_DATA_CMD = (*pWriteBuf++);
		}
	}
	while((I2C_CheckFlagState(I2Cx, BIT_IC_STATUS_TFNF)) == 0);
	I2C_MasterRead(I2Cx, pReadBuf, Readlen);
}