I2C-bus ROM API - repeated start

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I2C-bus ROM API - repeated start

430 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by brownm on Wed Oct 15 19:11:49 MST 2014
Hi all

I'm trying to use the ROM API for the i2C bus in the 11u68,

I am using the LPCOpen example project "periph_i2c_rom_interrupt" as a basis for my code.

I can read and write single bytes (and no doubt multiple bytes - however my device doesn't have these)

I need to issue a repeated start command to read the next register of the device (MAX9611), I have tried setting the stop_flag in the params struct to false. but that causes the I2C to lockup at the interrupt handler.

Any ideas on what the stop_flag actually does - I can't find any documentation on it?
Any ideas on how to issue a repeated start command.


/* 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, &param, &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];
}
}









it hangs here in the handler (but not if stop_flag == true)

void I2C1_IRQHandler(void){
/* Call I2C ISR function in ROM with the I2C handle */
LPC_I2CD_API->i2c_isr_handler(i2cHandleMaster);
}






Thanks and Regards

Marshall
Labels (1)
0 Kudos
Reply
0 Replies