static void readDateI2CMaster(uint16_t AddressI2C, int *date)
{
uint8_t recvData[10], sendData[10];
I2C_PARAM_T param;
I2C_RESULT_T result;
ErrorCode_t error_code;
int sindex = 0, rindex = 0;
sendData[sindex++] = (uint8_t) AddressI2C | 0x00;
sendData[sindex++] = (uint8_t) 0x00;
recvData[rindex++] = (uint8_t) AddressI2C | 0x01;
param.num_bytes_send = 2;
param.num_bytes_rec = 1;
param.buffer_ptr_send = &sendData[0];
param.buffer_ptr_rec = &recvData[0];
param.stop_flag = 1;
#if defined(INTERRUPTMODE)
param.func_pt = cbI2CComplete;
#endif
/* Set timeout (much) greater than the transfer length */
LPC_I2CD_API->i2c_set_timeout(i2cHandleMaster, 100000);
/* Do master read transfer */
#if defined(INTERRUPTMODE)
intErrCode = -1;
/* Function is non-blocking, returned error should be LPC_OK, but isn't checked here */
error_code = LPC_I2CD_API->i2c_master_receive_intr(i2cHandleMaster, ¶m, &result);
/* Sleep until transfer is complete, but allow IRQ to wake system
to handle I2C IRQ */
while (intErrCode == -1) {
__WFI();
}
/* Cast saved error code from callback */
error_code = (ErrorCode_t) intErrCode;
#else
error_code = LPC_I2CD_API->i2c_master_receive_poll(i2cHandleMaster, ¶m, &result);
#endif
/* Completed without erors? */
if (error_code != LPC_OK) {
/* Likely cause is NAK */
DEBUGOUT("i2c_master_receive error code : %x\r\b", error_code);
errorI2C();
}
*date = (int) recvData[1];
}
|