Interrupts with NRF24LE1
In our daily life we get distracted or interrupted by others many times. In that condition we suspend our ongoing work and pay attention to what others have to say. We only resume our previously suspended work after the completion of the interrupted task. The master which controls the processing of thoughts in us is our brain. The brain stops processing ongoing thoughts when we get interrupted and starts processing the other task. It resumes the previous ongoing processing when the task is complete. The controller works in a similar manner. Here, we will study interrupts associated with our NRF.
We all know the task of interrupts in any controller. It tells the microcontroller to suspend its current execution of code, save the current state and process interrupt request. Controller processes interrupt request by jumping to Interrupt Service Routine (ISR) or Interrupt Handler. ISR is a function or procedure defined in the code which gets executed when interrupt occurs. Same is the case with NRF.
In NRF24LE1, there are total 18 sources for interrupts out of which 4 are hardware based and the rest are software based. Each Interrupt source has a vector address at which ISR has to be written. These interrupts can be level triggered (Low/High) or Edge triggered (Rise/Fall).
The attached image consists of different sources, vector address, polarity and their description.
In 32 pin package, there are 2 external hardware interrupts: INT0 and INT1. Interrupt pin for INT0 is P0.5 and for INT1 is P0.6.
Interrupts can be controlled through various registers detailed below :
• Interrupt Enable 0 Register (IEN0) – An 8-bit register used to enable/disable global interrupts and Timer0, Timer1, Timer2, Port 0 and Serial Port individual interrupts.
• Interrupt Enable 1 Register (IEN1) – An 8-bit register used for enabling/disabling RF, SPI and Timer2 interrupts.
• INTEXP – This register enables/disables 2 wires, master and slave SPI interrupts. This register is also used to choose between INT0, INT1 and INT2.
• IP0 and IP1 (Interrupt Priority) – Two 8-bit registers used to set the priority levels among different sources.
• Interrupt Request Control Register (IRCON) – An 8-bit register this register contains interrupt request flags.
For software interrupt, we need to enable them according to functionalities we are using. For example, if we are using Timers then we will enable Timer interrupt which is associated with the internal timers of our module.
Presently we are focused on discussing hardware interrupts INT0. Some simple steps through which we can configure INT0 are-:
• First write 1 in bit7 of IEN0 to enable global interrupts and 1 in bit0.
• Write 1 in bit3 of INTEXP to select INT0.
• We have to write ISR for INT0
We have also written a code to explain the working of interrupt INT0. Besides, an LED blinking program has been written in our interrupt service routine. So the LED will blink whenever an interrupt occurs.
Check out the commented code for more details. Stay tuned for more articles in the series.