Electronic – I2C EEPROM only first attemt to read correct

i2c

I have very strange problem in my circuit. Namely, I have 24LC01 EEPROM connected to my PIC32. I made "library" for reading from and writing to the memory. What is happening is that only first reading of data gives me correct data, while every later attempt gives me wrong data.
The experiment is following. I wrote one page with 0x30 (0 Ascii character), so from address 0 – 7. Next I read 8 bytes starting from address 0. First reading is correct and I print 00000000. Next attempt to read fives me 0 and 7 unknown characters. This happens in the same manner until MC is restarted.

Here are some waveforms.

On the first wave, you can see that control word is sent, it was ACKed by the slave, then comes the memory address at which to start, in this case 0. Then comes ACK and repeated start event. Next, control word is sent again, but this time with reading flag set. After follows first charcter 0x30, and so on, till the 8th.

First read, start of communication.

At the end if the first reading attempt, you can see that NACK after the last byteis sent, followed by the STOP condition on the bus.

enter image description here

Next, you can see start of communication of the second attempt. First control word is sent correct and was ACKed. Next came address where the data should be read from (again 0), it was also ACKed. Next master sends repeated reading command, and the second control word with reading flag set (btw address of the device is 1010xxx). The second control word was also ACKed, and the came first byte from the memory location 0, which is 0x30 and as you can see it is also ok, but at the end of that byte SDL goes high and stays there till the end of the reception.

enter image description here

On the next photo is shown the end of the wave. As you can see SDL was always high, and only STOp condition is sent at the end.

enter image description here

What might be the problem here?

Best Answer

The problem was wrong assumption that flag to set ACK/NACK will be reseted after I disable I2C pin. So, the firmware was wrong.

So at the end of the first reading cycle the flag for NACK is set, and never changed back to ACK.