This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How can I avoid sending a repeated start between TWI write and TWI read?

I am communicating with a temperature sensor (MLX90614), which has flag register. However, in order to read this register, I must send a read sequence without issuing the repeated start between the write and read operations. Here is what I want to do in a step-by-step approach:

  1. Send start
  2. Send the slave address ID with the nWrite bit low (8 bits)
  3. Receive an ACK from the slave
  4. Send out the command to read the flags, 0xF0 (8 bits)
  5. Receive an ACK from the slave
  6. Do not send a repeated start. (Normally, there would be a repeated start here).
  7. Send the slave address with the nWrite bit high, indicating a read (8 bits)
  8. Send out 16 bits of clock to read in the MSB and LSB from the slave, placing ACKs appropriately.
  1. Issue a stop.

I think that I need to use GPIOTE with PPI to get this to work, but do not know how to specify the number of toggles that would be needed to describe the event. And upon describing the event, what action should be taken.

Can someone advise?

Thank you,

Noah

  • I had the same challenges in reading the flag register in the mlx90614. The datasheet of the mlx90614 says that only read/write word of the SMBUS standard 2.0 protocol is supported, while for the flag register read it does only state "Behaves like read command... The difference between read and read flags is that the latter does not have a repeated start bit". Based on that info your sequence seems to be interpreted correctly.

    However, in a preliminary application note (see e.g. www.pololu.com/.../MLX90614_SMBus.pdf) there is a figure for the communication flow and the following pseudo code for the read of the flag register:

    Pseudo code example: Flags reading

    1. Send START bit
    2. Send SLA+W
    3. Send Command 0xF0
    4. Read Data Byte Low (master must send ACK bit)
    5. Read Data Byte High (master must send ACK bit)
    6. Read PEC (master can send ACK or NACK)
    7. Send STOP bit

    I.e. it is not only the repeated start bit that is omitted, but also the SLA+R. After the mlx90614 has acknowledged the 0xF0 command it immediately start to transmit its flag register data. It seems to me that the Master have to change state from MasterTransmit (MT) to MasterRead (MR) in between step 3 and 4. I'm using the twi hw in my microcontroller (which works flawlessly for the read/write word), but changing from MT to MR (repeated start followed by SLA+R) without following the std SMBUS protocol seems to be impossible. I solved it by implementing some code based on the code found in the above referred application note to take control of the SDA/SCL in sw in the case of reading the flag register (not use the twi hw flow control).

Related