i2c transfer keep busy in the event handler

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

i2c transfer keep busy in the event handler

1,963 Views
samchen_tw
Contributor III

Hi 

I am using NXP OM13088 develop board.

I try example usbd_rom_hid_generic combined with i2c transfer.

I want to do i2c transfer in endpoint handler

/* HID Interrupt endpoint event handler. */
static ErrorCode_t HID_Ep_Hdlr(USBD_HANDLE_T hUsb, void *data, uint32_t event)
{
 USB_HID_CTRL_T *pHidCtrl = (USB_HID_CTRL_T *) data;
 unsigned int report_pending = 0;
 uint8_t ch[2];
 switch (event) {
 case USB_EVT_IN:
  DEBUGOUT("USB_EVT_IN\r\n");
#if 1
  DEBUGOUT("HID_Ep_Hdlr HID_REPORT_INPUT_i2c!\r\n");
  I2C_XFER_T xfer;
  i2cDev = I2C1;
  xfer.slaveAddr = 0x38;
  xfer.rxBuff = ch;
  xfer.txBuff = 0;
  xfer.txSz = 0;
  xfer.rxSz = 1;
  Chip_I2C_MasterRead(i2cDev, xfer.slaveAddr, xfer.rxBuff, xfer.rxSz);
#endif
  DEBUGOUT("HID_Ep_Hdlr End of HID_REPORT_INPUT\r\n");
  report_pending = 0;
  break;

I run this code, and found the device would be stuck in the Chip_I2C_EventHandler. The status is keeping I2C_STATUS_BUSY. 

void Chip_I2C_EventHandler(I2C_ID_T id, I2C_EVENT_T event)
{
 struct i2c_interface *iic = &i2c[id];
 volatile I2C_STATUS_T *stat;
 /* Only WAIT event needs to be handled */
 if (event != I2C_EVENT_WAIT) {
  return;
 }
 stat = &iic->mXfer->status;
 /* Wait for the status to change */
 while (*stat == I2C_STATUS_BUSY) {printf("Chip_I2C_EventHandler is busy\r\n");}
}
Please help how to fix it.
Thanks.
Tags (2)
7 Replies

1,684 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

Please download the LPCOpen  software for OM13088 (LPCXpresso4367 Development Board) from here.

There provides I2C master interrupt/polling demo with below path:

..\lpcopen_3_02_keil_iar_xpresso4337\LPC43xx_18xx\examples_43xx_18xx\periph_i2cm_interrupt

..\lpcopen_3_02_keil_iar_xpresso4337\LPC43xx_18xx\examples_43xx_18xx\periph_i2cm_polling

Please refer above demos about I2C master application.

Wish it helps.


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

1,684 Views
samchen_tw
Contributor III

Hi Mike

Thanks for your suggenstion. 

I found that we can't do i2c transfer in the usb interrupt handler.

I causes dead lock for waiting i2c interrupt handler.

Thanks.

Sam

0 Kudos
Reply

1,684 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Sam,

You can set a I2C transfer flag at usb interrupt service routine.

The I2C transfer flag will trigger I2C transfer, when exit the usb service routine.

Wish it helps.


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

1,684 Views
samchen_tw
Contributor III

Hi Mike

Would you please help provide sample codes for setting I2C trasnfer flag?

Thanks for your help.

Sam

0 Kudos
Reply

1,684 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Sam,

What I mentioned I2C transfer flag is just a volatile global variable.

The I2C communication is slow, which shouldn't take place in USB interrupt service routine.

Thank you for the attention.

best regards,

Mike

1,684 Views
samchen_tw
Contributor III

Hi Mike

That's clear.

I will try i2c transfer in other place.

Thanks. 

Sam

0 Kudos
Reply

1,684 Views
samchen_tw
Contributor III

By the way, from oscilloscope, I saw the i2c scl from hight to low and keeping low forever.

Thanks.

0 Kudos
Reply