0

I believe I've understood the concept of interrupt and how to initialize it, but I've seen in various places where they would first AND (select) the NVIC_PR registers against F bits before (ORing) the priority bits. For example in TM4C123 GPIO Port Interrupt Programming there was this line towards the end:

NVIC_PRI7_R = (NVIC_PRI7_R & 0xFF00FFFF) | 0x00A00000 

The purpose is to set Port F interrupt a priority of 5 (by setting the top 3 bits [23:21] to the value; hence .1010. or 0xA to represent the a value of 5). So, why can't I just do this instead?

NVIC_PRI7_R |= 0x00A00000 

What is & 0xFF00FFFF doing here? Why do I want to clear bits [23:16] before OR-ing priority bits [23:21]? The bits between [20:16] are not used anyway.

1 Answer 1

2

If bits [23:21] were all already set to 1, then NVIC_PRI7_R |= 0x00A00000 does nothing, it doesn't set them to the value you want, they all stay as 1s, that's why you clear them before applying your mask. The & with 0xFF00FFFF ensures that only the bits [23:16] are modified, the rest are left as they were.

Sign up to request clarification or add additional context in comments.

2 Comments

If [23:21] were already set to 1, regardless of whether NVIC_PRI7_R |= 0x00A00000 causes any actual change of bits wouldn't matter to the end result - that is [23:21] will be 1's and that's all that matter (unless there are some sort of edge-triggering here?). Second is if we were to explicitly clear NVIC_PRI7_R register, shouldn't I be doing this: NVIC_PRI7_R & 0x00000000? Alternatively if I were to keep other bits unaffected and clear just [23:21], shouldn't that be NVIC_PRI7_R & 0xFF0FFFFF to clear [23:21] specifically instead of the double zero 00 clearing out [23:16]?
If you're wanting to set the priority to 5 by setting those bits to 101, but they're already 111 then you end up with priority 7, that may or may not be a problem in your application. You're right, if you're only interested in those 3 bits you could & 0xFF1FFFFF, without studying the datasheet more I don't know why the linked article suggests &0xFF00FFFF

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.