English
Language : 

AT42QTAN0040 Datasheet, PDF (13/14 Pages) ATMEL Corporation – Driving the AT42QT2160 QMatrix Sensor IC
Driving the AT42QT2160
/*=====================================================================================
Function:
ReadQtI2c() Executes multi-byte read from QT-device
Input:
SlaveAddress = Device address on the I2C bus
ReadAddress = Register address
ReadLength = Number of bytes to read
ReadPtr = Pointer to byte array for read-data
Output:
I2C_OK if transfer completes, I2C_FAIL if device NACKs
====================================================================================*/
uint8_t ReadQtI2c ( uint8_t SlaveAddress,
uint8_t ReadAddress, uint8_t ReadLength, uint8_t *ReadPtr )
{
uint8_t i, Result;
/* write address-pointer to device */
Result = WriteQtI2c ( SlaveAddress, ReadAddress, 0, 0 );
if ( Result == I2C_OK )
{
do { /* attempt to address device until ACK is received */
SendSTART;
if ( (Result = SendByte ( (SlaveAddress << 1) + READ_FLAG) ) != I2C_OK )
SendSTOP;
} while ( Result != I2C_OK );
do {
*ReadPtr++ = GetByte ( --ReadLength );
} while ( ReadLength );
SendSTOP; /* terminate transfer */
}
return Result;
}
/*--------------------------End of I2C Driver ---------------------------------------*/
13
10702A–AT42–07/08