Q on mega 0-series TWI slave protocol

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Hi All,

 

I'm working on a state transition diagram for slave mode I2C software.  I've started with the read part.  See diagrams below.

Here is the question: Say the I2C master is reading 3 bytes, but the slave thinks it's only supposed to return two, what happens after the master sends the ACK for the second byte?  It seems the but is now is a deadlock.  The master is waiting for data and the slave is waiting for a stop command.   I must be missing something.  I'm asking about the "n=0/???" branch in the diagram.

 

 

here is the associated diagram from the megaAVR0 datasheet:

 

This topic has a solution.
Last Edited: Tue. Jun 16, 2020 - 07:54 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The slave must send something when the master clocks the data, what is sent is undefinded, but it must send something (repeat last data sent, 0x00, 0xff, ???)

Refer to the I2C doc from Phillups NXP for details of the protocol. 

The slave releases the bus when the master NAK's, but until then it sends data.

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk, thank BTW 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
Refer to the I2C doc from Phillups NXP for details of the protocol

Always!

 

https://www.nxp.com/docs/en/user-guide/UM10204.pdf

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

new version w/ write loop added and "send zero" on n==0