2
\$\begingroup\$

When I was trying to read 0xF8 from slave, the SDA is still low.

b"0111_0000", -- 38 slave address (write)
b"0000_0000", -- 00 register address
b"1000_1111", -- 8F data
b"0111_0000", -- 38 slave address (write)
b"1010_0100", -- A4 register address
b"0000_0000", -- 00 data (enable interrupt to host)
b"0111_0000", -- 38 slave address (write)
b"1000_0000", -- 80 register address (describe valid touching detect threshold) 
b"0000_1111", -- 0F data   
b"0111_0000", -- 38 slave address (write)
b"1000_1000", -- 88 register address (describe valid touching detect threshold) 
b"0000_1100", -- 0C data       
b"0111_0000", -- 38 slave address (write)
b"1010_0001", -- A1 register address
b"0111_0001", -- 38 slave address (read)
b"0111_0000", -- 38 slave address (write)
b"1010_0010", -- A2 register address        
b"0111_0001", -- 38 slave address (read)

Whole code initialization used by the master is above.

Datasheet of the slave chip is here (https://threefivedisplays.com/wp-content/uploads/datasheets/touch_driver_datasheets/FT5206_REV_0_4_%20APP.pdf)

As you can see from the datasheet, this IC is used by touch screen to read touch value.

You can see that from the first picture that the SDA is low even though SCL is high for quite a while. The message I am trying to send is a stop according to IIC protocol.

it's not going high

You can see from 2nd picture when I was trying to read 0x30 from slave, the slave is high.

enter image description here

The 3rd picture shows that SDA goes high anyway after one second (very long time) when read value is 0xF8. enter image description here

Scope diagram of the IIC is here.

enter image description here

Second oscilloscope diagram is here.

enter image description here Can anyone explain what happened here?

\$\endgroup\$
13
  • \$\begingroup\$ It would help if you edit your question to give a little more context about what devices these are, and what you're doing with them. It's possible someone who knows I2C better than me can answer from just what you've provided, but often it will depend on the behavior of the specific device. \$\endgroup\$ Nov 28, 2023 at 19:53
  • \$\begingroup\$ Likely a bug in your master source code. But without knowing which MCU this is, what code it runs, and what the slave chip is, it's impossble to answer. \$\endgroup\$
    – Justme
    Nov 28, 2023 at 19:55
  • 1
    \$\begingroup\$ @GlennWillen I have just uploaded the link for the datasheet of the slave. \$\endgroup\$
    – kile
    Nov 28, 2023 at 20:12
  • \$\begingroup\$ @Justme I have just uploader link for the datasheet of the slave. \$\endgroup\$
    – kile
    Nov 28, 2023 at 20:13
  • 1
    \$\begingroup\$ Your rising edges are all suspiciously sharp for I2C, unless your clock speed is very slow and/or your pullups are very strong. Are you sure you have your I2C master's pins correctly configured in open-drain mode? \$\endgroup\$
    – brhans
    Nov 28, 2023 at 21:02

1 Answer 1

4
\$\begingroup\$

When you have transferred the last byte you want to read, you ACK the byte.

That is incorrect, you must NAK the last byte.

If you ACK the byte, the slave IC thinks you want to receive a next byte too and starts transmitting it out. So that is why SDA is low and you can't send out a stop, because you can't release the SDA after setting SCL high if the slave is keeping the SDA low.

If you NAK the byte, the slave will no longer drive any data out after the NAK, leaves the SDA floating high, and the FPGA is free to pull SDA down, release SCL high, and release SDA.

\$\endgroup\$
4
  • \$\begingroup\$ I really appreciate your help! this problem bothers me for a week. But why does it work if the read data is other than 0xF8 even when master send ack? \$\endgroup\$
    – kile
    Nov 28, 2023 at 21:44
  • \$\begingroup\$ @kile That's because after ACK there is already first bit of next byte on the bus, and when reading register index 0xA1 it returns data bytes 0x30 and something with MSB high next; while reading register index 0xA2 it returns data bytes 0xF8 and something with MSB low. If the registers are as usual and register index is auto-incrementing, you could assume reading two bytes starting from index 0xA1 will return data from 0xA1 and 0xA2 so in fact after 0x30, there could be 0xF8, and there could be something with MSB 0 on 0xA3. \$\endgroup\$
    – Justme
    Nov 28, 2023 at 21:53
  • \$\begingroup\$ How can I see the MSB bit of next byte? Is it possible to see the MSB bit? \$\endgroup\$
    – kile
    Nov 29, 2023 at 8:11
  • \$\begingroup\$ @kile You are already seeing it if you send ACK bit, as after ACK bit the slave is already transmitting out the MSB of the next byte you did not want. \$\endgroup\$
    – Justme
    Nov 29, 2023 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.