Confusion about TWI interrupt on tinyAVR 2

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

Hello, I've been reading documentation about master mode TWI of tinyAVR 2 and found TWI Master Operation diagram. It seems to indicate that interrupt is only raised before M1 and M2. When reading the description of M4 I've noticed that it also seems to raise the interrupt. Does M4 raise the interrupt? If M4 raises the interrupt what is the meaning of "Interrupt flag raised" diamond on the diagram? I've added relevant images to the attachments, I had problem with adding them directly to the post. 

 

Attachment(s): 

This topic has a solution.
Last Edited: Fri. Jul 23, 2021 - 06:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Assuming tinyAVR2 is similar to the AVR-0 series, with which I am familiar, the interpretation is that the associated flag is set in the status register and if the associated interrupt is enabled, it is triggered.  If the interrupt is not enabled, you should be polling the associated status register.

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

MattRW wrote:

Assuming tinyAVR2 is similar to the AVR-0 series, with which I am familiar, the interpretation is that the associated flag is set in the status register and if the associated interrupt is enabled, it is triggered.  If the interrupt is not enabled, you should be polling the associated status register.

That also seems to be the case in tinyAVR2. I'm just confused about the meaning of "Interrupt flag raised" diamond because it's not present in every place the interrupt flag is raised so it seems meaningless.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are only 2 interrupts- read and write, RIF/RIEN and WIF/WIEN, so nothing of interest (where you need to do something) happens until either of those flags are set. Once you get an R/WIF flag then its time to check all the flags.

 

You can treat these flags 'simply' if wanted-

for a RIF, if STATUS == RIF|CLKHOLD|OWNER , then is a 'good' read interrupt

for WIF, if STATUS == WIF|CLKHOLD|OWNER , then is a 'good' write interrupt

anything else is an error of some kind, and in most cases it does not matter much why the flags are not correct, you simply try again.