Clear Status Flags during ISR

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Clear Status Flags during ISR

Jump to solution
1,965 Views
whata
Contributor III

Hi, 

I'm using a MKL26Z128VLH4  (I'm using KSDK 2.2 and MCUXpresso 10.0) in a application where I have multiple peripherals working in a interrupt based fashion and I have a copuple of questions: 

1. When multiple peripherals operating in interrupt mode is it necessary to set-up interrupt priorities by using NVIC?

NVIC_SetPriority ()

2. After looking at the examples for various peripherals I see that in several peripherals the source of the interrupt is not cleared during the ISR, such as UART example \boards\frdmkl26z\driver_examples\uart\interrupt. Is that kind of usage correct? I thought that interrupt source needs to be cleared prior to exiting the ISR to avoid having false re-entry. Or is reading back the status register somehow automatically clears pending interrupt source flags? 

So, for instance, during the PIT interrupt is the following piece of code correct? Or should I do a read on status before clearing the flag? I'm a bit confused on general guidelines for correctly exiting the ISRs.

/*!
 * @brief Interrupt handler for timer
 */
void PIT_IRQHandler (void) {
     PIT_ClearStatusFlags (PIT, kPIT_Chnl_1, kPIT_TimerFlag);
     PIT_StopTimer (PIT, kPIT_Chnl_1);
}‍‍‍‍‍‍‍‍‍‍‍‍
Labels (1)
Tags (3)
0 Kudos
1 Solution
1,452 Views
mjbcswitzerland
Specialist V


Hi

If you don't set a priority of each interrupt it will have the default. It is not usually a problem to not set priorities because like that they will all have the same and simply won't be able to interrupt each other; normally this is fine.

You need to check each peripheral's method of clearing interrupts - some need a read before resetting a flag. Some just need a flag reset (writing 0 or 1, again depending on the peripheral) and some are self-clearing when data is read, for example.

The PIT example may be overly simple because there are multiple PIT channels in the KL26 and so there may be more than one that has interrupted at the same time; the code should check the ones that need handling.

Regards

Mark

http://www.utasker.com/kinetis/FRDM-KL26Z.html
http://www.utasker.com/kinetis/TEENSY_LC.html

View solution in original post

1 Reply
1,453 Views
mjbcswitzerland
Specialist V


Hi

If you don't set a priority of each interrupt it will have the default. It is not usually a problem to not set priorities because like that they will all have the same and simply won't be able to interrupt each other; normally this is fine.

You need to check each peripheral's method of clearing interrupts - some need a read before resetting a flag. Some just need a flag reset (writing 0 or 1, again depending on the peripheral) and some are self-clearing when data is read, for example.

The PIT example may be overly simple because there are multiple PIT channels in the KL26 and so there may be more than one that has interrupted at the same time; the code should check the ones that need handling.

Regards

Mark

http://www.utasker.com/kinetis/FRDM-KL26Z.html
http://www.utasker.com/kinetis/TEENSY_LC.html