AnsweredAssumed Answered

I2C driver, Read function can block

Question asked by arnogir on Oct 6, 2016
Latest reply on Nov 4, 2016 by arnogir

Hello,

 

I'm on a Kinetis K70 with an I2C device (to manage tactile screen)

 

To be faster, this device can accept an "immediate" read: We don't sent adress where we want read, by this, we automatically receive the touch screen coordinate.

To do this, I wrote the following code:

 

Param = MySlaveAddress;

ioctl(fd, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &Param);

 

Param = 4;
Error = ioctl(fd, IO_IOCTL_I2C_SET_RX_REQUEST, &Param);

 

/* Read all data */
  ReturnValue = 0;
  do
  {
    ReturnValue += fread(&BufferPtr[ReturnValue], 1, 4- ReturnValue, fd);
  }
  while (ReturnValue < 4);

 

When peripheral not connected (or with problem), the ACK after "START + SlaveAddress + R" is a NACK.

But we not detect it and then the first "fread" return 0 (because 0 byte read), with the while, we call again the fread which in this case never return..

 

How can we detect the NACK between FIsrt byte (START + SLA +R) and first read Byte?

With oscilloscope, all 5 pulses clock (1 start + 4 Bytes) are sent on the call of first "fread" (when all work correctly with an ACK).

When Nack, only first pulse clock is sent with  NACK.

Outcomes