/* Sends data and read data in master mode through the USIx peripheral.  */
void USI_I2C_MasterRepeatRead(USI_TypeDef *USIx, u8 *pWriteBuf, u8 Writelen, u8 *pReadBuf, u8 Readlen)
/* Sends data and read data in master mode through the USIx peripheral.  */
void USI_I2C_MasterRepeatRead(USI_TypeDef *USIx, u8 *pWriteBuf, u8 Writelen, u8 *pReadBuf, u8 Readlen)
{
	u8 cnt = 0;
	assert_param(IS_USI_I2C_ALL_PERIPH(USIx));
	for(cnt = 0; cnt < Writelen; cnt++)
	{
		while((USI_I2C_CheckTXFIFOState(USIx, USI_TXFIFO_ALMOST_EMPTY_COPY)) == 0);
		if(cnt >= Writelen - 1)
		{
			USIx->TX_FIFO_WRITE = (*pWriteBuf++) | (1 << 10);
		}
		else
		{
			USIx->TX_FIFO_WRITE = (*pWriteBuf++);
		}
	}
	while((USI_I2C_CheckTXFIFOState(USIx, USI_TXFIFO_ALMOST_EMPTY_COPY)) == 0);
	USI_I2C_MasterRead(USIx, pReadBuf, Readlen);
}