Example #1
0
/*
 *  This function reads the slave device's register
 *
 *  Parameters:
 *      deviceAddress   - i2c Slave device address which register
 *                        to be read from
 *      registerIndex   - Slave device's register to be read
 *
 *  Return Value:
 *      Register value
 */
unsigned char hwI2CReadReg(
	unsigned char deviceAddress,
	unsigned char registerIndex
)
{
	unsigned char value = (0xFF);

	if (hwI2CWriteData(deviceAddress, 1, &registerIndex) == 1)
		hwI2CReadData(deviceAddress, 1, &value);

	return value;
}
Example #2
0
/* 
 * This function read the i2c device register value
 *
 * Input:   deviceAddress   - I2C Device Address
 *          registerIndex   - Register index to be read
 *
 * Output:
 *          The value of the register being read.
 */
unsigned long hwI2CReadRegMultiple(
    unsigned char deviceAddress,
    unsigned char registerIndex,
    unsigned long length,
    unsigned char *pBuffer
)
{
    unsigned long totalData = 0;

    /* The length is limited to 256 since register index is limited to unsigned char. */
    if ((registerIndex + length) > 256)
        length = 256 - registerIndex;

    /* Read from the slave device */
    if (hwI2CWriteData(deviceAddress, 1, &registerIndex) == 1)
        totalData = hwI2CReadData(deviceAddress, length, pBuffer);
    
    /* Return the total number of read data */
    return totalData;
}