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.

MSP430FR5949 PORT4 Interrupt Vector

Other Parts Discussed in Thread: MSP430FR5949

Hi all

I am having trouble with servicing routines on VECTOR4 of the MSP430FR5949 ucontroller.

I am using the experimenter board MSP-EXP430FR5949 and I am trying to setup the switch on P4.5 to fire an interrupt and toggle the LED on P4.6

I use the following settings.

  P4OUT = BIT5;                             // Pull-up resistor on P4.5
  P4REN = BIT5;                             // Select pull-up mode for P4.5
  P4DIR = BIT6;                             // Set all but P4.6 to input direction
  P4IES = BIT5;                             // P4.5 Hi/Lo edge
  P4IFG = 0;                                // Clear all P4 interrupt flags
  P4IE = BIT5;                              // P4.5 interrupt enabled

I then have the following interrupt routing which never seems to be called when pressing the switch.

// Port 4 interrupt service routine
#pragma vector=PORT4_VECTOR
__interrupt void Port_4(void)
{
  P4IFG = 0;                            // Clear P4 IFG
 
  switch(P4IV)
    {
    case 0:
      break; // No Interrupt
   
    case 2:
      break; // P4.0
   
    case 4:  // P4.1
      break;
     
    case 6:  // P4.2
      break;
   
    case 8:  // P4.3
      break;
   
    case 10: // P4.4
      break;
   
    case 12: // P4.5
     
      if (ucCalON==0) 
      {
        ucCalON = 1;
        P4OUT = BIT6;
      }
      else
      {
        ucCalON = 0;
        P4OUT = 0;
      }
     
      break;
   
    case 14: // P4.6
      break;
   
    case 16: // P4.7
      break;
    }
}

Any ideas what's going on here people? The manual P4IV is serviced the same way as P1 and that works fine

  • Hi David!

    // Port 4 interrupt service routine
    #pragma vector = PORT4_VECTOR
    __interrupt void Port_4( void )
    {
      P4IFG = 0; // Clear P4 IFG
     
      switch( P4IV )
      {
        case 0:
          break; // No interrupt
        ...
      }
    }

    If you first clear P4IFG and then try to read P4IV, the program will jump into case 0 because there is no pending flag anymore. Clearing P4IFG isn't required because reading P4IV automatically clears the highest pending flag.

    Also keep in mind that buttons and switches do not have perfect on/off bevaviour - they are bouncing until they reach their final state. This means that multiple interrupts can occur until final state and this happens in a very short time that you might not notice. Imagine the LED toggles 0-1-0-1-0-1-0 for a single action - it would look like nothing happened, but it actually did. Some sort of debouncing would be useful. To test the interrupt in general I would recommend to first initialize the LED as off and only switch it on in the interrupt, not toggling it. If that works, go on...

    Dennis

    Dennis

  • Table 6-3 of the datasheet says:

  • It's OK. I have cracked it. I should have been using bit operators on the particular bit I wanted to set/clear. Instead I was setting the whole of PORT4 and changing the settings
  • , that is interesting. According to the datasheet, P4.5 has interrupt capability:

    Does that mean you have to test P4IFG for all port interrupts higher than P4.2 instead of using P4IV? Would reading P4IV clear this pending flag although it cannot be used to service it? Sounds strange.

    Dennis

  • If table 6-3 were correct, pins P4.3…7 would not be interrupt capable at all. But I guess that "P4IFG.2" is just a copy&paste error from some other chip that has only three P4 pins.
  • Clemens Ladisch said:
    But I guess that "P4IFG.2" is just a copy&paste error from some other chip

    Would be my guess as well. , does reading P4IV work with P4.5?

**Attention** This is a public forum