lpcopen i2c driver and interrupts

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

lpcopen i2c driver and interrupts

1,083 Views
perencia-wc
Contributor II

Hi everyone,

I find the i2c driver in the last lpcopen (LPCOpen v3.02 release (Released: 12/21/2017)) misleading regarding the support of interrupt-driven transfers.

Though they seem to be supported, and even there is an example in periph_i2c/i2c.c, the fact is that you are forced to do a busy wait until the transfer is finished, which actually breaks the purpose of using interrupts in the first place. If you skip the busy wait in the event handler, trying to do other useful things while the xfer is in progres, you end up setting the xfer to NULL in Chip_I2C_MasterTransfer, which makes it impossible for handleMasterXferState to finish it.

 

iic->mEvent(id, I2C_EVENT_WAIT);
iic->mXfer = 0;

 

I think the wait should only be in Chip_I2C_EventHandlerPolling and the line that sets mXfer = 0 removed. That way the user could pass its own handler and decide if he or she wants to do a busy wait or not. 

Best regards.

 

0 Kudos
Reply
4 Replies

1,066 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

First of all, can you tell us the part number you are using?

Furthermore, can you post all the project so that we can know the issue?

BR

XiangJun Rong

0 Kudos
Reply

1,063 Views
perencia-wc
Contributor II

Hi,

This has nothing to do with a part number. It is just a suggestion to future versions of the LpcOpen, because I think it doesn't handle the i2c interrupts properly. It is all in the library code, I'd say the very example projects illustrate my point.

Regards.

0 Kudos
Reply

1,056 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I suppose you refer to the following api function, the while (!isI2CBusFree(iic->ip)) {} line will counteract the interrupt advantage.

BR

XiangJun Rong

/* Transmit and Receive data in master mode */
int Chip_I2C_MasterTransfer(I2C_ID_T id, I2C_XFER_T *xfer)
{
struct i2c_interface *iic = &i2c[id];

iic->mEvent(id, I2C_EVENT_LOCK);
xfer->status = I2C_STATUS_BUSY;
iic->mXfer = xfer;

/* If slave xfer not in progress */
if (!iic->sXfer) {
startMasterXfer(iic->ip);
}
iic->mEvent(id, I2C_EVENT_WAIT);
iic->mXfer = 0;

/* Wait for stop condition to appear on bus */
while (!isI2CBusFree(iic->ip)) {}

/* Start slave if one is active */
if (SLAVE_ACTIVE(iic)) {
startSlaverXfer(iic->ip);
}

iic->mEvent(id, I2C_EVENT_UNLOCK);
return (int) xfer->status;
}

0 Kudos
Reply

1,052 Views
perencia-wc
Contributor II

Hi

Not actually. It is the line before. if you look at Chip_I2C_EventHandler you'll see that it does a busy wait until the xfer has finished. If you do not do it, then you'll get to iic->mXfer = 0; and the interrupt code won't be able to advance because the mXfer is no longer valid. That is why you are forced to do a busy wait on the handler. In my case, I want the main loop to continue while the transfer goes on, but I can't because of that.

0 Kudos
Reply