ATmega4808/9 TWI: Address Packet Transmit Complete - Address not Acknowledged by Slave ?

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

A TWI protocol question, please!

 

In The megaAVR-0 series Family Data Sheet, 40002015C.pdf, Section 24.3.4.2.2, "Transmitting Address Packets", the case of an address packet without an ACK is discussed. Since this can easily happen if the wrong address is used or if the addressed device is not connected to the bus, this  seems like a pretty important case. The spec sheet says:

 

If no slave device responds to the address, the Master Write Interrupt Flag (WIF in TWIn.MSTATUS) and the Master Received Acknowledge Flag (RXACK in TWIn.MSTATUS) are set. The RXACK flag reflects the physical state of the ACK bit (i.e.< no slave did pull the ACK bit low). The clock hold is active at this point, preventing further activity on the bus.

However, there is no statement about appropriate actions. I could see having to change the bus state to allow further actions, or clearing the RXACK flag. I could also see issuing a  STOP. Or, maybe just charge on with a new START with some other address?  Or, maybe something entirely different?

 

So, you TWI users out there: what do you do?

 

Thanks

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Wed. Feb 19, 2020 - 06:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim, I have not used the new 0/1 avrs, but on the megas, if the start fails due to an NAK (slave not answering), then I would send a stop and return a failed status(for the I2c read/write function) so a retry could be scheduled at a later time.

Jim

 

 

 

 

 

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

Thanks!

 

The 4808/9 TWI port implementation seems a bit different compared to earlier AVRs. That is what I did, previously, also. The behavior of the status register, and what gets reset when, is one of the big differences. So, I was hoping that someone who has been through the swamp might have some insight.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

In Dieter's I2C code for 0/1 avr, he also sends stop:

status = I2C_wait_ACK();										// wait for slave ACK
	if (status == 1) {
		I2C_stop();													// NACK, abort
		return 1;

I did not dig any further to see how flags are handled, so this exercise is left up to the student! smiley

Jim

 

 

 

 

 

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

Microchip provided the TWI files for Arduino. They have a Microchip license (e.g., not lgpl, more like bsd but MC only), so I don't see a good reason to avoid that file.

 

https://github.com/arduino/ArduinoCore-megaavr/blob/master/libraries/Wire/src/utility/twi.c

 

It does this "If NOT acknowledged (NACK) by slave cancel the transaction.", but I need to confess my ignorance.

 

https://github.com/arduino/ArduinoCore-megaavr/blob/master/libraries/Wire/src/utility/twi.c#L435

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

Thanks, both of you!

 

Will carefully inspect the code, esp Arduino since MC had a hand in it.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net