Example #1
0
int I2C_SW::read_regs(uint8_t SlaveAddress, uint8_t startRegister, uint8_t*out, int count)
{
	int i;

	if (!I2C_Start()) {
			return -1;
	}

	I2C_SendByte(SlaveAddress&0xFE);

	if (!I2C_WaitAck()) {
			I2C_Stop();
			return -1;
	}

	I2C_SendByte(startRegister);
	I2C_WaitAck();

	I2C_Start();
	I2C_SendByte((SlaveAddress&0xFE)|0x01);
	I2C_WaitAck();

	for(i=0; i<count; i++)
	{
		out[i] = I2C_ReceiveByte();
		if (i==count-1)
			I2C_SendNoAck();
		else
			I2C_SendAck();
	}

	I2C_Stop();
	
	return 0;
}
Example #2
0
// Read data via I2C. 
BOOL I2C_ReadBytes(BYTE* Buf, BYTE Len, BYTE I2cDevice)
{
	while(Len--)
	{
		*(Buf++) = I2C_ReadByte(I2cDevice);
		if(Len == 0)
		{
			I2C_SendNoAck(I2cDevice);
		}
		else
		{
			I2C_SendAck(I2cDevice);
		}
	}

	return TRUE;
}