I am currently working on an I2C EEPROM project using bit-banging to drive the SDA and SCL lines.
My read function works fine but whenever I write any byte with a leading "1", I always read FF back; even if the byte has been programmed with something else before. Leading "0" is perfect. It is not my read routine; as I can see on the scope it returns FF.
I am looking for suggestions on why this might be. Is there any obvious I could miss which could cause the problem? [I cannot post the code – company confidential… :(]
Every waveform I look at meets the spec exactly. I am decoupling the EEPROM. My pull ups are 2.2k so within spec. I'm clocking at about 500 Hz in this prototype. The chip is sending ACKs to each of my bytes so it recognises them. But it just doesn't work…
I am using a Microchip 24LC256.
Simplified writing algorithm for one byte:
wait
SDA low
SCL low
wait
for each bit
if bit is set: SDA high
if bit is unset: SDA low
wait
SCL high
wait
wait
SCL low
wait
wait
SDA high
SCL high
wait
wait
check ACK status
SDA low
SCL low
wait
return ACK status
Simplified reading algorithm for one byte:
wait
SCL low
SDA high
for each bit (8 bits)
SCL high
wait
wait
SCL low
wait
check and store received bit
wait
do a NACK or ACK depending on if it is the last byte
Best Answer
You're reading the data after clock is low again. You'll have to do that between making the clock high and making it low. After the clock is low the slave is allowed to change the data line, not while it's high.
So reading should be like this: