The I2C spec specifies that when a master is performing a read from a
slave, the master must not acknowledge the last byte before issuing a
stop condition (ie: it NAKs rather than ACKs).
In contrast, during a write, the slave is supposed to generate an
acknowledge for each byte received (if it can correctly receive the
byte) until it receives a stop condition.
It is not clear to me why the master must not acknowledge reception of
the last byte read even thought this
byte was received correctly. Should'nt the master acknowledge the last
byte, indicating it was received okay, then issue a stop to signal it's
done?
I have seen code which generates ACKs for all bytes (as master) and the
peripheral chips seem to work fine, but I am not comfortable doing this
when the spec says otherwise.
It is not obvious to me why the spec would insist on this behaviour.
Any comments, insights, musings, etc. would be welcome.
Regards,
Daniel Quinz, P. Eng.
Micronetics CES
e-mail: da...@micronetics-ces.com
The NAK tells the slave transmitter to let go of control of the SDA line so
that the master can send a STOP. If the NAK was not sent, the slave
transmitter would try to send another byte (bit) while the master was trying
to send the STOP. The NAK lets the master take control of SDA to send the
STOP.
I hope this helps.
Myron Tuttle
myron_...@hp.com
mtu...@slip.net
Daniel Quinz wrote in message <36BB60...@micronetics-ces.com>...
>I have a question that perhaps someone here might have an answer to.
>
>The I2C spec specifies that when a master is performing a read from a
>slave, the master must not acknowledge the last byte before issuing a
>stop condition (ie: it NAKs rather than ACKs).
>.....
I was asking myself the same question. I thought it more logical to ACK the
last byte then issue STOP.
I found a pdf file detailing the spec on the Phillips web site.
The ACK/NAK is in the 9th bit position. Following the 8 bits of the last
byte I do not send the 9th bit at all, but force a stop condition. It seems
to work fine. The data sheet does show the 9th bit before the stop. The
slave sees the data line high, so stop is close enough to NAK.
The EEPROM data sheet says that the device looks for a low (ACK) during the
9th bit position. If not low, it terminates the operation.
Some slaves might not like the missing 9th bit, I think I'll try a NAK after
the last byte.
Regards
Paul Bealing
Daniel Quinz wrote in message <36BB60...@micronetics-ces.com>...
>I have a question that perhaps someone here might have an answer to.
>
>The I2C spec specifies that when a master is performing a read from a
>slave, the master must not acknowledge the last byte before issuing a
>stop condition (ie: it NAKs rather than ACKs).
>
>In contrast, during a write, the slave is supposed to generate an
>acknowledge for each byte received (if it can correctly receive the
>byte) until it receives a stop condition.
>
>It is not clear to me why the master must not acknowledge reception of
>the last byte read even thought this
>byte was received correctly. Should'nt the master acknowledge the last
>byte, indicating it was received okay, then issue a stop to signal it's
>done?
>
>I have seen code which generates ACKs for all bytes (as master) and the
>peripheral chips seem to work fine, but I am not comfortable doing this
>when the spec says otherwise.
>
>It is not obvious to me why the spec would insist on this behaviour.
>
>Any comments, insights, musings, etc. would be welcome.
>
> It is not clear to me why the master must not acknowledge reception of
> the last byte read even thought this byte was received correctly.
> Should'nt the master acknowledge the last byte, indicating it was
> received okay, then issue a stop to signal it's done?
No, ACK means "send more" for the slave and it will do so. If the next
bit of that transmission is a zero then the master is unable to issue
a STOP condition (SDA high during SCL high).
The only way to get the slave off-line is issuing NAK at the end of the
final byte.
Yeah, that's it. To make it more clear: If you ACK the last byte, the slave
prepares to send another byte by putting it's first bit on SDA. If this bit
is low, the SDA line is clogged and the master is not able to send a stop.
Learned that the hard way.
--
Olav "Mac" Wölfelschneider wo...@cardware.de
PGP fingerprint = 06 5F 66 B3 2A AD 7D 2D B7 19 67 3C 95 A7 9D AF
Mer muß doch nur emol e bissje nochdenke. -- Mundstuhl
Thanks. I was re-reading the specs on the PIC16C73 and I noticed a
similar desription of events.
Regards,
Dan
>
> The NAK tells the slave transmitter to let go of control of the SDA line so
> that the master can send a STOP. If the NAK was not sent, the slave
> transmitter would try to send another byte (bit) while the master was trying
> to send the STOP. The NAK lets the master take control of SDA to send the
> I found a pdf file detailing the spec on the Phillips web site.
Email only, not posted in the newsgroup.
I was following this thread because of an impending
need to implement some I2C eeprom. From the Microchip
data sheets I *thought* I had a grasp of it. But......
Can you give a URL for that website where you found
that pdf file?
Thanks.
--
Tony Williams.
<snip>
>
> Can you give a URL for that website where you found
> that pdf file?
>
> Thanks.
Hi Tony.
You can get the pdf file from philips website at the following address:
http://www-us2.semiconductors.philips.com/i2c/facts/#specification
Regards,
Daniel Quinz, P. Eng.
Micronetics CES
> > I found a pdf file detailing the spec on the Phillips web site.
> Email only, not posted in the newsgroup.
And guess which fool hit the wrong bloody key
to send it. :(
--
Tony Williams.
> Hi Tony.
> You can get the pdf file from philips website at the following address:
> http://www-us2.semiconductors.philips.com/i2c/facts/#specification
Got it thanks, 24 pages of good stuff.
--
Tony Williams.
I wonder if I could describe the sequence brick-by-brick,
to see if my interpretation of the Phillips I2C data
sheet is correct.......
We are talking master-receiver, the master is generating
SCL as a series of low-highs, low-highs, etc. During
each low the slave sets SDA to the req'd state, and the
master reads that state during the highs.
At the end of bit8, the master sets SCL low, and presumably
this causes the slave to release SDA. During the low period
of bit9 the master can pull down SDA to ACK, or leave it
high to NACK. During the high period of bit9 the slave
reads which way was set.
Now, a STOP is defined as a low-high transition of SDA
whilst SCL is high.
But, and here's where I staggered, to NACK during bit9
it had to set SDA high, so SDA is now in the wrong state
to do a simple low-high transition.
The master has to drop SCL (therefore starting a bit10),
and, during that low, set SDA low, then raise SCL, then
raise SDA. (with req'd timings of course)
I cannot actually see any other way doing a STOP.
Is this correct?
--
Tony Williams.
Yes thank you. Useful things, newsgroups. :)
--
Tony Williams.