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.

MSP430FR6047: P3IN example doesn't work. Please help.

Part Number: MSP430FR6047


I'm having difficulty of breaking out of while loop through a port interrupt. When the execution point is inside this while loop, the port interrupt doesn't work any more.

So, when back and played with the first example code provided by TI and tried as below;

//   Evan Wakefield
//   Texas Instruments Inc.
//   October 2016
//   Built with IAR Embedded Workbench V6.50 & Code Composer Studio V6.2
//******************************************************************************
#include <msp430.h>

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer

    // Configure GPIO
    P1DIR |= BIT0;                          // Set P1.0 to output direction

    // Disable the GPIO power-on default high-impedance mode to activate
    // previously configured port settings
    PM5CTL0 &= ~LOCKLPM5;

    while (1)                               // Test P1.3
    {
        if (P3IN & BIT0)
            P1OUT |= BIT0;                  // if P1.3 set, set P1.0
        else
            P1OUT &= ~BIT0;                 // else reset
    }
}

1. But the P3IN register value is always FF even if I press P3.0. What is going on?

2. And in the code of my project, the register value in the register viewer changes to FE. But scanning the value in the code didn't update accordingly.

3. And in the code of my project, when the execution is being done outside of this 'while loop', the '__interrupt void PORT3_ISR(void)' works just fine. What's going on?

Thank you in advance.

  • Hi,

    Which example code did you test?

  • It's the first sample in the list, "msp430fr60x7_ta0_01.c". I modified it a little bit to adapt it for P3.0. 

    But the phenomenon I'm experiencing is really strange. Don't you think?

  • Try turning optimization off.

    It is almost like P3IN is not being declared volatile.

  • I turned if off but still no luck.

    I even added the followings just to be sure;

    P3SEL0=0;
    P3SEL1=0;
    P3DIR=0;
    P3REN|=BIT0;

    It didn't help either, as you can imagine.

    I solved my original problem by an alternative method.


    But it makes me scratch the back of my head.

    Because

    1.  Port3 Interrupt is working just fine and dandy, i.e;

      #pragma vector=PORT3_VECTOR
    __interrupt void PORT3_ISR(void)

    2. I remember  running this code without problem whatsoever long time ago without bothering to change -optimization stuff.

    I know I must be doing something wrong. But I can't seem to find it.

  • Did you try more pins? If you're having similar issues on multiple pins, it's most likely a code issue.

  • Like you think I didn't try more pints? C'mon. Of course I did.

    In my project, I use P3.0, 1, 2 and 3 as button inputs. And they are WORKING JUST FINE (I mean Port_ISR is working.), when they are not in WHILE loop. 

    You said "It's most likely a code issue." Then please look at the code I presented yourself and tell me if there's anything wrong. It's just a simple code to scan P3.0. 

    And let me ask you. Don't you think it's strange that P3.0 Tto P3.3 doesn't change value, while Port interrupt is working? That is the core of my question, I guess. So, please enlighten me from this perspective.

    Thank you for your time...

  • Code can mean two things. The first being your high level C code and the second being the machine language that the CPU executes. For example:

          while (1)                               // Test P1.3
        {
            if (P3IN & BIT0)
        445e:       d2 b3 20 02     bit.b   #1,     &0x0220 ;r3 As==01
        4462:       05 24           jz      $+12            ;abs 0x446e
    
    00004464 <.L8>:
                P1OUT |= BIT0;                  // if P1.3 set, set P1.0
        4464:       d2 d3 02 02     bis.b   #1,     &0x0202 ;r3 As==01
    
    00004468 <.Loc.46.1>:
            if (P3IN & BIT0)
        4468:       d2 b3 20 02     bit.b   #1,     &0x0220 ;r3 As==01
        446c:       fb 23           jnz     $-8             ;abs 0x4464
    
    0000446e <.L6>:
            else
                P1OUT &= ~BIT0;                 // else reset
        446e:       d2 c3 02 02     bic.b   #1,     &0x0202 ;r3 As==01
        4472:       f5 3f           jmp     $-20            ;abs 0x445e
    

  • David. Thank you for your kind reply. But I'm sure that there's no problem with the code.

    Today I came back to office from home where I've been coding for the whole last week for vacation. In the office, I have another exactly same board. This has never been loaded with any code at all. It's like fresh out of the box.

    I loaded the same example code on this board and it's working just fine, just like I anticipated.

    So, I suspect that my project code did something that somehow cripples the port reading function. I'll load my project code on this board and see if the same thing happens with this board, too.

    I'll come back after the test.

  • I load the my project code and then loaded the example code again.

    But this one is reading the port as it should. I don't know what's wrong with the board at home...

    Anyways, thanks guys.

**Attention** This is a public forum