This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432P401R - need some help with setting interrupts in the NVIC register



Hi everyone!

I'm working with the MSP432 LaunchPad now and I want to use the ADC14.

I must admit, that migrating to the new 432 family isn't that easy for me as I am only used to the 430 so far. Never used something like the startup-file.

I plan to use the interrupt from the ADC14 module.

What I did so far: From the code examples I could get an idea of what I have to change, so I opened the header file for the P401R and searched for

INT_ADC14

this is 40. Now I opened the startup file and added

/* External declarations for the interrupt handlers used by the application. */
extern void ADC14_ISR_Handler( void );
/* To be added by user */

I also added

...
defaultISR,                                /* EUSCIA3 ISR               */
defaultISR,                                /* EUSCIB0 ISR               */
defaultISR,                                /* EUSCIB1 ISR               */
defaultISR,                                /* EUSCIB2 ISR               */
defaultISR,                                /* EUSCIB3 ISR               */
ADC14_ISR_Handler,                         /* ADC14 ISR                 */
defaultISR,                                /* T32_INT1 ISR              */
defaultISR,                                /* T32_INT2 ISR              */
defaultISR,                                /* T32_INTC ISR              */
defaultISR,                                /* AES ISR                   */
...

and this is located at entry 40 in this list now (starting from 0). Another question here: Why is there

defaultISR                                 /* Reserved 64               */

listed in the table? I would understand 63, but why 64? The user's guide says, the NVIC controller can handle up to 64 interrupts, so 0 to 63.

Or is it because 0 means no pending interrupt and therefore it is 1 to 64?

In the main.c I added

void ADC14_ISR_Handler( void )
{
  // Future ADC14 ISR code
}

And now I do not understand this line

NVIC_ISER0 = 1 << ((INT_ADC14 - 16) & 31);         // Enable ADC interrupt in NVIC module

I understand that there are two 32 bit registers for NVIC, giving 64 bits in total. We will now use the lower NVIC register, so 0 to 31. The operation performed there is the following

NVIC_ISER0 = 1 << ((INT_ADC14 - 16) & 31);         // Enable ADC interrupt in NVIC module

NVIC_ISER0 = 1 << ((40 - 16) & 31);
NVIC_ISER0 = 1 << (24 & 31);
NVIC_ISER0 = 1 << (0001 1000 & 0001 1111); // 24 & 31
NVIC_ISER0 = 1 << 0001 1000; // 24
NVIC_ISER0 = 1 << 24;
NVIC_ISER0 = 0000 0001 0000 0000 0000 0000 0000 0000;

The "& 31" is to ensure that the number is not greater than the maximum of 31 bits in the lower NVIC register. I looked at another code example for a timer module and there it was

NVIC_ISER0 = 1 << ((INT_TA0_N - 16) & 31);

So almost identical with exception of INT_TA0_N which is 25 - this would lead to a bit shift of 9, setting the 10th bit in NVIC_ISER0. So why is always 16 subtracted?

And what would happen if I had

INT_DMA_INT0

for example? This is 50 and would lead to

NVIC_ISER0 = 1 << ((INT_DMA_INT0 - 16) & 31);

NVIC_ISER0 = 1 << ((50 - 16) & 31);
NVIC_ISER0 = 1 << (34 & 31);
NVIC_ISER0 = 1 << (0010 0010 & 0001 1111); // 34 & 31
NVIC_ISER0 = 1 << 0000 0010; // 2
NVIC_ISER0 = 1 << 2;
NVIC_ISER0 = 0000 0000 0000 0000 0000 0000 0000 0100;

Can someone explain?

Thanks in advance!

Dennis

  • Hi Dennis,

    Dennis Eichmann said:

    Why is there

    defaultISR                                 /* Reserved 64               */

    listed in the table? I would understand 63, but why 64? The user's guide says, the NVIC controller can handle up to 64 interrupts, so 0 to 63.

    You are correct, this seems like an error to me, but it shouldn't affect anything, except for taking unnecessary space of memory. I'll submit the bug anyways.

    Dennis Eichmann said:
    So almost identical with exception of INT_TA0_N which is 25 - this would lead to a bit shift of 9, setting the 10th bit in NVIC_ISER0. So why is always 16 subtracted?

    The reason is that the first 16 interrupts include some NMI interrupts, Reset and Initial SP value, and the "user" interrupts start at 16. So, the PSS ISR which is really the first maskable interrupt (0) which can be enabled/disabled by NVIC_ISERx has an INT_PSS value of 16.

    You can check a generic table of MSP432 interrupts in Figure 1-5 of SLAU356A; and the user interrupts for MSP430P401R in Table 6-12 of SLAS826A.

    Dennis Eichmann said:

    And what would happen if I had

    INT_DMA_INT0

    for example?

    NVIC_ISER0 enables maskable interrupts 0 to 31, while NVIC_ISER1 enables maskable interrupts 32 to 63. 

    As you mention, INT_DMA_INT0 has a value of 50, but the offset is really 50-16=34 (as shown in Table 6-12 of SLAS826A).

    Since the offset is >31, this interrupt is enabled in NVIC_ISER1 instead of NVIC_ISER0. But the value that you got is correct, since this interrupt will be enabled in NVIC_ISER0.BIT2

    Regards,

    Luis R

  • Luis RC,

    thank you very much for explaining - now it is clear to me!

    Dennis

**Attention** This is a public forum