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.

MSP 432 Interruption whit button

Hello, I would like to use the interruption method #"pragma vector " for the MSP432, I've found examples only for the MSP430, when I try to use the next code y get the error :

"Description    Resource    Path    Location    Type
#2622 The symbol used in #pragma vector= requires a declaration    main.c    /pruebainterrupcion    line 36    C/C++ Problem
"

//////THE CODE

#include <msp.h>   // original <msp430.h>
#include <inttypes.h>
 
int i=0;
int T=30000;
 
void main(){
	WDTCTL= WDTPW+WDTHOLD;
	P1SEL= 0x00;
	P1DIR|= (BIT0+BIT6);
	P1DIR&=~BIT3;
	P1REN|=BIT3;
	P1IE|=BIT3;      
	P1IES|=BIT3;
	P1IFG&=~BIT3;
	P1OUT|=BIT0;
	P1OUT&=~BIT6;
	_BIS_SR(GIE);    
 
while(1){                
	for(i=0;i<T;i++);
	P1OUT^=BIT6;
	P1OUT^=BIT0; 
	if(T<=1500){T=30000;}
}
}
                                      
#pragma vector= PORT1_VECTOR                
__interrupt void Led_ISR (void){
	P1IFG&=~BIT3;                    
	T=T-2000;
}

Also I was looking in the MSP432™ Platform Porting Guide, there in secction 4.2.3.1 I've found that there are 3 steps for enabling interruptions(RTCPS1CTL |= RTP1PSIE;SCS_NVIC_ISER=INT_RTC_BIT;__enable_interrupt())
The second one is an extra step for the MSP432, but even the other two that are suppose to be used in the MSP430 are no defined in the example code that is functional.
That is confusing, I just want to make a simple interruption like on the example code.

Thanks!!!!!






  • Hi Josue, send your question to the experts on the subject!

     

     


    Regards Martin.

  • Hi Josue!

    Are you using CCS? And did you start your new project as a MSP432 one?

    I'm wondering if the compiler doesn't complain about

    P1SEL = 0x00;

    and

    _BIS_SR( GIE );

    as well?

    There is no register named P1SEL, so your compiler should tell you that it is undefined. Instead there are P1SEL0 and P1SEL1.

    _BIS_SR( x ) should be declared implicitly and GIE should also be undefined. Use

    __enable_interrupt();

    instead.

    I have written a small program for you that uses the button S1 at P1.1 to toggle the LED1 at P1.0 on the MSP-EXP432P401R LaunchPad using the interrupt for S1 and a software delay to debounce the button (not recommended to use the software delay in a real program, but good enough for testing the interrupt):

    #FreeSampleCode 

    #include <msp432p401r.h>
    #include <stdint.h>
    
    
    // LED1      @ P1.0
    // Button S1 @ P1.1
    
    
    volatile uint8_t  button_flag = 0;                         // Flag to signal button press
    volatile uint32_t deb_cnt;                                 // Counter for debouncing button
    
    
    void main( void )
    {
      WDTCTL = (WDTPW | WDTHOLD);                              // Stop watchdog timer
    
      P1SEL0 = 0x00;                                           // Clear selection register 0 for port 1
      P1SEL1 = 0x00;                                           // Clear selection register 1 for port 1
    
      P1REN  = 0x02;                                           // Enable resistor for S1 (P1.1)
      P1OUT  = 0x02;                                           // S1 (P1.1) high -> pull-up resistor, others low
      P1DIR  = 0x01;                                           // LED1 (P1.0) to output direction, others input
    
      P1IES  = 0x02;                                           // Interrupt on high->low transition for S1 (P1.1)
      P1IFG  = 0x00;                                           // Clear any pending flags
      P1IE   = 0x02;                                           // Enable interrupt for S1 (P1.1)
    
      NVIC_ISER1 = 1 << ((INT_PORT1 - 16) & 31);               // Enable interrupts for port 1 in the NVIC module
    
      __enable_interrupt();                                    // Enable global interrupts
    
      while( 1 )                                               // Endless loop - main program
      {
        if( button_flag )
        {
          P1OUT ^= 0x01;                                       // Toggle LED1 (P1.0)
          for( deb_cnt = 0; deb_cnt < 20000; deb_cnt++ );      // Software delay for debouncing button - NOT TO USE IN A REAL PROGRAM
          button_flag = 0;                                     // Reset flag
          P1IFG &= ~0x02;                                      // Clear pending interrupt flag for S1 (P1.1)
          P1IE |= 0x02;                                        // Enable interrupt for S1 (P1.1)
        }
      }
    }
    
    
    void port1_ISR_handler( void )                             // Interrupt handler for port 1
    {
      P1IE &= ~0x02;                                           // Disable interrupt for S1 (P1.1) for debouncing
      button_flag = 1;                                         // Set flag to signal button press detected
    }

    And these are the changes you have to make in the startup file:

    ...
    /* External declarations for the interrupt handlers used by the application. */
    extern void port1_ISR_handler( void );
    /* To be added by user */
    
    
    /* Interrupt vector table.  Note that the proper constructs must be placed on this to  */
    /* ensure that it ends up at physical address 0x0000.0000 or at the start of           */
    /* the program if located at a start address other than 0.                             */
    #pragma RETAIN(interruptVectors)
    #pragma DATA_SECTION(interruptVectors, ".intvecs")
    void (* const interruptVectors[])(void) =
    {
      ...
      defaultISR,                             /* DMA_INT0 ISR              */
      port1_ISR_handler,                      /* PORT1 ISR                 */
      defaultISR,                             /* PORT2 ISR                 */
      ...
    };

    Dennis

  • Hi Dennys, thank you very much for your answer, I use the free code that you send me to make my code, but I still have problems. The next code doesn't have any errors:

    #include <msp432p401r.h>
    #include <stdint.h>
    #include <inttypes.h>

    int i=0; //Variables.
    int T=30000;

    void main(){

    WDTCTL= WDTPW+WDTHOLD;

    P1SEL1= 0x00;
    P1DIR|= (BIT5); //OUTPUTS

    P1DIR&=~BIT6; //INPUT
    P1REN|=BIT6; //Pull-down

    P1IES = BIT6; // Interrupt on high->low transition for S1 (P1.1)
    P1IFG = 0x00; // Clear any pending flags
    P1IE = BIT6; // Enable interrupt for S1 (P1.1)

    P1OUT|=BIT5;

    NVIC_ISER1 = 1 << ((INT_PORT1 - 16) & 31); // Enable interrupts for port 1 in the NVIC module

    __enable_interrupt(); // Enable global interrupts

    while(1)
    {

    for(i=0;i<T;i++); //primer for
    P1OUT^=BIT5;
    if(T<=30000/2){T=30000/2;} //segundo if

    }
    }

    void port1_ISR_handler( void ) // Interrupt handler for port 1
    {
    P1IE &= ~0x02; // Disable interrupt for S1 (P1.1) for debouncing
    T=T/2; // Set flag to signal button press detected
    }

    What I want to do is to reduce the delay to make the external LED blink faster using interruptions. When I push the interruption button, the Led maintains the last state but does not blink faster. I am new in everything that concerns microcontrolers. Thank you very much for your help.


    Also I dont really understand for what I use:

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


    /* Interrupt vector table. Note that the proper constructs must be placed on this to */
    /* ensure that it ends up at physical address 0x0000.0000 or at the start of */
    /* the program if located at a start address other than 0. */
    #pragma RETAIN(interruptVectors)
    #pragma DATA_SECTION(interruptVectors, ".intvecs") */ What "interruptVectors" is and should be????
    void (* const interruptVectors[])(void) =
    {
    ...
    defaultISR, /* "WHAT IS THIS PART FOR??" */
    port1_ISR_handler, /* PORT1 ISR */
    defaultISR, /* PORT2 ISR */
    ...
    };

    Thank you very much!!!!
  • Josue Pareja said:
    Also I dont really understand for what I use [...]

    Then first you should understand this. The MSP432 has a different way of handling interrupts. When creating a new MSP432 project, a file is generated that is named:

    msp432_startup_ccs.c

    In this file you add your interrupt functions. You can name your function as you like - I called the interrupt function for the code example

    void port1_ISR_handler( void )

    and you find it under the main() function. The startup file contains a table with all the possible interrupts. You now have to tell, which function shall be executed for which interrupt. So you have to add the function's name a) in the interrupt vector table and b) in the external declarations with adding an extern attribute to the function because it resides in another function (your main.c in that case).

    Here is a picture:

    The red arrows mark the startup file. You open it by double-clikcing on the file in the project explorer located on the left (like for any other file of your project). The blue arrows show the two places where you have to make the changes (the last picture shows the same interrupt vector table as the one before, but scrolled down to the entry of PORT1 ISR where you have to insert your function).

    Dennis

    Note: When posting code, please always use the Syntaxhighlighter </> which can be found in rich formatting mode. It appears on the lower right after pressing on reply.

**Attention** This is a public forum