/* Master transmit/receive in interrupt mode */
static void sendReadI2CMaster(uint16_t AddressI2C, uint8_t *DataInPtr, uint8_t regAddr, uint8_t num_bytes_to_read, bool stop_flag_set){
uint8_t recvData[10], sendData[10];
I2C_PARAM_T param;
I2C_RESULT_T result;
ErrorCode_t error_code;
int sindex = 0, rindex = 0;
/* Setup I2C send for address/send, send desired LED state, then stop */
/* Setup I2C receive for address/read, read desired LED state, then stop */
/* 7-bit address */
sendData[sindex++] = (uint8_t) AddressI2C;
recvData[rindex++] = (uint8_t) AddressI2C | I2C_RD_CMD_BIT;
sendData[sindex++] = (uint8_t) regAddr;
/* Setup parameters for transfer */
param.num_bytes_send = sindex;
param.num_bytes_rec = rindex;
//param.num_bytes_rec = num_bytes_to_read-1;
param.buffer_ptr_send = &sendData[0];
param.buffer_ptr_rec = &recvData[0];
//param.stop_flag = 1;
param.stop_flag = stop_flag_set;
param.func_pt = cbI2CComplete;
/* Do master read transfer */
intErrCode = -1;
/* Function is non-blocking, returned error should be LPC_OK, but isn't checked here */
error_code = LPC_I2CD_API->i2c_master_tx_rx_intr(i2cHandleMaster, ¶m, &result);
//BADNESS OCCURS HERE IF stop_flag = false
/* 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;
/* Completed without errors? */
if (error_code != LPC_OK) {
/* Likely cause is NAK */
DEBUGOUT("i2c_master_tx_rx error code : %x\r\b", error_code);
errorI2C();
}
else {
/* Note results are only valid when there are no errors */
*DataInPtr++ = recvData[0];
*DataInPtr++ = recvData[1];
}
}
|