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.

MSP430FR2422: Reconfigure an analog pin as Digital pin

Part Number: MSP430FR2422

Hello,

In our application, we need to wake-up the MCU when there is a signal on pin P1.1 & then measure the voltage present on the same pin.

For this, we have followed below approach.

  1. configure Pin P1.1 as digital i/p pin
    - enable interrupt for the same
    - go to sleep mode (LPM0)
  2. upon wake-up, by interrupt on P1.1, reconfigure this pin as analog i/p channel A1
  3. calculate voltage on P1.1 using ADC & do other tasks
  4. Go to Point - 1

But, it doesn't work.
MCU wakes-up & performs the voltage calculation task, when interrupted on the pin P1.1 for the first time only.
After that, MCU doesn't generate interrupt on pin P1.1.

Can anyone help us to resolve this issue?
If there is an alternate approach to fulfill our application requirement, please share it with us.

Thank You

  • Hi Maunik,

    Make sure P1.1 is reconfigured as digital input pin and enable the interrupt.

    Can you share your source code?

    Ling

  • Hi Ling,

    Please find the code below.

    #include <msp430.h>
    
    void config_wakeup_pin(void);
    void config_analog_pin(void);
    
    void main (void)
    {
        WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
    
        // Configure LED Pin (P2.2) as output pin
        P2DIR |= BIT2;                            // Set P2.2 to output direction
        P2OUT &= ~BIT2;
    
        // configure IO1 Pin (analog input pin P1.1) as digital input, just before entering sleep mode
        // in active mode we'll configure this pin as analog input pin
        config_wakeup_pin();
    
        PM5CTL0 &= ~LOCKLPM5;                   // Disable the GPIO power-on default high-impedance mode
        __bis_SR_register(LPM0_bits | GIE);          // Enter LPM0 w/ interrupt
    
        while(1)
        {
            config_analog_pin();
     
    	/*
    	*	other operations
    	*/
    
            config_wakeup_pin();
            __bis_SR_register(LPM0_bits | GIE);          // Enter LPM0 w/ interrupt
            __no_operation();                     // Placeholder for while loop (not required)
        }
    }
    
    // Port 1 interrupt service routine
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {
        switch( __even_in_range( P1IV, P1IV_P1IFG7 )) {
            case P1IV_P1IFG1:                                       // Pin 1.1
                __bic_SR_register_on_exit(LPM0_bits);              // Clear CPUOFF bit from LPM0
                break;
            default:   _never_executed();
        }
    }
    
    void config_wakeup_pin(void)
    {
        P1REN |= BIT1;                            // Enable P1.1 internal resistance
        P1OUT &= ~BIT1;                            // Set P1.1 as pull-Up resistance
        P1IES &= ~BIT1;                           // P1.1 Lo/Hi edge
        P1IFG &= ~BIT1;                           // P1.1 IFG cleared
        P1IE |= BIT1;                             // P1.1 interrupt enabled
    }
    void config_analog_pin(void)
    {
        // Configure ADC A1 pin
        SYSCFG2 |= ADCPCTL1;
        SYSCFG2 |= ADCPCTL0 | ADCPCTL2;	    // we are using External reference voltage for ADC
        
    
        // Disable the GPIO power-on default high-impedance mode to activate
        // previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    
        // Configure ADC10
        ADCCTL0 |= ADCSHT_2 | ADCON;                              // ADCON, S&H=16 ADC clks
        ADCCTL1 |= ADCSHP;                                        // ADCCLK = MODOSC; sampling timer
        ADCCTL2 |= ADCRES_1;                                        // 10-bit conversion results
        ADCMCTL0 |= ADCINCH_1;                        // A1 ADC input select
        ADCMCTL0 |= ADCSREF_7;                        // Vref= external voltage
    
        // Configure reference
        PMMCTL0_H = PMMPW_H;                                      // Unlock the PMM registers
        PMMCTL2 |= EXTREFEN;                                      // Enable external reference
        __delay_cycles(400);                                      // Delay for reference settling
    }

  • #include <msp430.h>
    
    void config_wakeup_pin(void);
    void config_analog_pin(void);
    
    void main (void)
    {
        WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
    
        // Configure LED Pin (P2.2) as output pin
        P2DIR |= BIT2;                            // Set P2.2 to output direction
        P2OUT &= ~BIT2;
    
        // configure IO1 Pin (analog input pin P1.1) as digital input, just before entering sleep mode
        // in active mode we'll configure this pin as analog input pin
        config_wakeup_pin();
    
        PM5CTL0 &= ~LOCKLPM5;                   // Disable the GPIO power-on default high-impedance mode
        __bis_SR_register(LPM0_bits | GIE);          // Enter LPM0 w/ interrupt
    
        while(1)
        {
            config_analog_pin();
    
            /*
             *   other operations
             */
    
            config_wakeup_pin();
            __bis_SR_register(LPM0_bits | GIE);          // Enter LPM0 w/ interrupt
            __no_operation();                     // Placeholder for while loop (not required)
        }
    }
    
    // Port 1 interrupt service routine
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {
        switch( __even_in_range( P1IV, P1IV_P1IFG7 )) {
        case P1IV_P1IFG1:                                       // Pin 1.1
            P2OUT ^= BIT2;                                      //Toggle LED
            __bic_SR_register_on_exit(LPM0_bits);               // Clear CPUOFF bit from LPM0
            break;
        default:   _never_executed();
        }
    }
    
    void config_wakeup_pin(void)
    {
        PMMCTL0_H = PMMPW_H;                                      // Unlock the PMM registers
        PMMCTL2 &= ~EXTREFEN;                                     // Disable external reference
    
        SYSCFG2 &= ~ADCPCTL1;
    
        P1REN |= BIT1;                            // Enable P1.1 internal resistance
        P1OUT &= ~BIT1;                           // Set P1.1 as pull-down resistance
        P1IES &= ~BIT1;                           // P1.1 Lo/Hi edge
        P1IFG &= ~BIT1;                           // P1.1 IFG cleared
        P1IE |= BIT1;                             // P1.1 interrupt enabled
    
    }
    void config_analog_pin(void)
    {
        // Configure ADC A1 pin
        SYSCFG2 |= ADCPCTL1;
        SYSCFG2 |= ADCPCTL0 | ADCPCTL2;     // we are using External reference voltage for ADC
    
        // Configure ADC10
        ADCCTL0 |= ADCSHT_2 | ADCON;                                // ADCON, S&H=16 ADC clks
        ADCCTL1 |= ADCSHP;                                          // ADCCLK = MODOSC; sampling timer
        ADCCTL2 |= ADCRES_1;                                        // 10-bit conversion results
        ADCMCTL0 |= ADCINCH_1;                                      // A1 ADC input select
        ADCMCTL0 |= ADCSREF_7;                                      // Vref= external voltage
    
        // Configure reference
        PMMCTL0_H = PMMPW_H;                                      // Unlock the PMM registers
        PMMCTL2 |= EXTREFEN;                                      // Enable external reference
        __delay_cycles(400);                                    // Delay for reference settling
    }
    

  • Hi Ling,

    You resolved my issue & the code is working fine now.

    Thanks for resolving my issue.
    Thanks a lot.

    Regards,
    Maunik Patel

**Attention** This is a public forum