AnsweredAssumed Answered

i2c transfer keep busy in the event handler

Question asked by Sam Chen on Jun 5, 2018
Latest reply on Jun 13, 2018 by Sam Chen

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.

Outcomes