manual clearing of INT flags

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

On an atmega32u4, I need to manually clear the OCF1A and OCF1B flags before enabling their respective interrupts. However, since writing a '1' clears the flag, if I do something like this...

TIFR1 |= (1<<OCF1B);

Then it seems like it would clear any other set bits in the TIFR1 register too. Mainly, I am interested in preserving the TOV1 bits state. But if TOV1 is set, then when TIFR1 gets written as TIFR1 OR'd with OCF1B (i.e. 0x04), it would write a '1' to that TOV1 location too (because it was alreasy set), there by clearing it! So how do you best handle this? I've always let the ISR handle clearing the flags and never put much thought into it until now.

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

Oh, wait a minute, if writing a '0' has no effect, then the following would leave all other flags untouched...

TIFR1 = (1<<OCF1B); 

Right? I guess you could also AND it with just the flags you want to clear. Like this...

TIFR1 &= (1<<OCF1B); 

Does this sound correct? Anyone got a preferred method?

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

Quote:
Right?
Yes.
Quote:
I guess you could also AND it with just the flags you want to clear. Like this...
Why bother when the direct "=" does what you want.

Regards,
Steve A.

The Board helps those that help themselves.