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.

migrating code from MSP430F1232 on earlier IAR compiler to MSP430F2132 with latest IAR compiler

Other Parts Discussed in Thread: MSP430F1232

After adjusting numerous register names in the UART and adding BCSCTL3 to the clock setup I find that the code compiles without errors or warnings but the interrupts do not operate any more.  I am using TIMER0 to generate a Real Time Clock and the UART for serial comms at 9600 Baud using interrupts.  At turn on the code used to output a sign-on message followed by a prompt.  Now it endlessly resets.

I'm using USCIAB0TX_VECTOR for the vector and checking for the required flag.  The sign-on message is triggered in background code by setting  IFG2 |= UCA0TXIFG;  but this results in immediate reset.

The general scheme worked flawlessly on the MSP430F1232 and earlier compiler and I'm at my wits end trying to sort out what I'm doing wrong.  It must be something really stupid!  I would very much appreciate a nudge in the right direction.  

Thanks.

  • It's not as easy to migrate from 1x to 2x. Some parts are identical or at least backwards compatible (ports and timers, even the ADCs), some things are different, like the migration form USART to USCI. One of the differences, IIRC, is that the USART has edge-triggered interrupts, the USCi has level-triggered interrupts. So if you don't clear the IFG bit that caused an interrupts (e.g. by reading RXBUF to clear RXIFG, or by manually resetting it), you'll go into an endless interrupt loop.
    Also, there are a lot more interrupt souces than before.

    However, your description of an endless resets rather looks liek you have enabled an interrupt but didn't write an ISR for it.
    Perhaps a mistake in the naming of the timer vectors?

    I had to take a look at your code to check it. (you can send it in a private conversation if you don't want to post it in the public, but provide a link to this thread so I can answer here)

  • Thanks very much for the response.  Using the dis-assembly listing I have verified that the interrupt vectors actually point to the service routines so below are segments of the code that should show what I'm doing wrong!

    unsigned int Flag = 0, Nominal = 999;
    unsigned int ThermV = 0, Supply = 0, Illum = 0;
    unsigned int Sample, Previous = 512, PrevPrev = 512, PrevPrevPrev = 512;
    unsigned int SumP2P = 0, Max = 0, Min = 512;
    unsigned int Ticks = 0, Intensity = 0, Sum4 = 0, Peak = 0;
    unsigned int Dividend, Divisor, Quotient, Mask;
    unsigned int Interrupts = 0, Span = 0, Digit = 0;
    unsigned int Degrees = 0, Decimal = 0, Minutes = 0, Remainder = 0;
    unsigned int RxPtr = 0, TxPtr = 0, ProcPtr = 0, LoadPtr = 31 ;
    unsigned int Factor = 0;

    char ZeroXptr = 0, Bright = 0, Count = 0, Sixths = 0, Trend = 127;
    char Top, Step, Index = 0, VoltsCode, VoltsUnits, VoltsDeci;
    char Temp = 0, Samples = 0, CharCount = 0, SampleCount = 0;
    char Plot[54] ;
    char RxBuf[8]= "       ";
    char TxBuff[32]= "  Sign-on message goes here     ";
    int Write(int);
    char Put(); // puts individual characters into the output buffer
    void Graph(); // plot the beam strength distribution

    void main(void)
    {
      void Init_Micro();
      Init_Micro();

      void Divide();  // Calculates a scaling factor at start-up
     // void ApplyScale();
      void Report();
      void Show();  // Generates the graphic plot
      void ShowV(); // Displays the raw supply voltage
      void ShowT(); // Displays temperature degrees C
      void Clock(); // A simple minutes of month clock
      IE2 |= (UCA0RXIE + UCA0TXIE); // Enable UART Rx & Tx interrupts
      IE2 &= 0xF3; // Disable other UART interrupts
      IFG2 &= ~UCB0TXIFG;
      TxBuff[29] = CR; TxBuff[30] = LF;
      _EINT(); // Enable global interrupts
      IFG2 |= UCA0TXIFG; // Trigger the Sign on message
      Flag |= Finished;
      for (;;) // Keep executing this loop while awaiting interrupts
        {
         if(P2IN & IN1) // Switch 1 in Running mode?

    ..........................

    void Setup_Ports()
    {
      // bit0 = Relay, bit1 = LED1, bit2 = PWM, bit3 = LED 2
      // bit4 = Tamper, bit5 = SW1, bit6 = SW2, bit7 = Sample
      P1SEL |= 0x04; // bit2 assigned to PWM, all others to pins
      P1SEL2 &= 0x04; //(Bit2 is set to primary periferal)
      P1REN = 0x00; // No pullups
      P1DIR |= 0x8F; // LEDs 1 & 2 + relay output + switches in.
      P1OUT &= ~(LED1 + LED2 + Relay); // Initialise LED display
      // bit 0 = Temp, bit 1 = Opto, bit 2 = V_panel, bit 3 = V_Charger
      // bit 4 = V_Bat.
      P2SEL |= 0xC0; // LO 5 bits to ADC.
      P2SEL2 &= 0xC0;
      P1REN &= 0x00; // No pullups
      P2DIR &= 0x00; // all bits are inputs.
      // bit0 = LDR, bit1 = Config, bit2 = Reg_En, bit3 = RS232_Status
      // bit4 = UART_TX, bit5 = UART_RX, bit6 = Ring_Indic, bit7 = RS232_En
      P3SEL |= 0x30; // bits 4 & 5 = UART I/O, bit 0 = ADC(LDR)
      P3DIR |= 0x84; // bits 7,6,4 & 2 are outputs
      P3OUT |= Serial_En; // turn the RS232 chip output ON.
    } // end of Setup_Ports
    void Setup_UART()
    {
      // Now set up the UART, NOTE THAT THIS DIFFERS FROM 1232
      UCA0CTL1 |= UCSWRST; // Hold the hardware in Reset during setup.
      UCA0CTL0 |= UC7BIT;
      UCA0CTL1 |= UCSSEL_1; // Set main clock.
      UCA0BR0 = 0xA1; // Divide 4mHz Clock by 417 for Baud rate = 9600
      UCA0BR1 = 0x01 ;
      UCA0MCTL = 0x00; // No modulation of the clock
      IE2 |= UCA0TXIE + UCA0RXIE; // Enable UART for Rx & Tx.
      UCA0CTL1 &= ~UCSWRST; // Remove the hardware reset and allow operation.
    } // end of setup UART


    .................


    #pragma vector = USCIAB0RX_VECTOR
    __interrupt void asart0rx(void)
    {
      char Temp;
      if(IFG2 & UCA0RXIFG) // UART Rx interrupt?
         {
          Temp = UCA0RXBUF; // Yes, read character.
          RxBuf[RxPtr++] = Temp; // Save it to buffer.
          if(RxPtr > 31)
             RxPtr = 0; // circular buffer.
          if(Temp == CR)
            Flag |= Reply;
          else
            Flag &= ~Reply;
          if(Temp == Question)
            Flag |= Distrib;
          else
            Flag &= ~Distrib;
         }
    }  // end of serial receive code

    #pragma vector = USCIAB0TX_VECTOR
    __interrupt void usart0tx(void)
    {
     if(IFG2 & UCA0TXIFG) // UART Tx Interrupt?
      {
       if(TxPtr != LoadPtr)
         {
           UCA0TXBUF = TxBuff[TxPtr++];
           if(TxPtr > 31)
             TxPtr = 0; // Circular buffer.
           if(CharCount > 0) // Keep track of buffer capacity
              CharCount--;
         }
       else
         Flag |= Finished;
       IFG2 &= ~UCA0TXIFG;
      }
    } // end of serial transmit interrupt

    Thanks again

  • Jens, Further testing has revealed the true nature of my problem.  It seems that I didn't check  TimerA for differences as the compiler didn't object to anything.  However, as you suggested in your initial response, it looked like I had an interrupt without an ISR to service it.  I also have a Real Time Clock based on TimerA & after turning all the other interrupts off one by one studying the documentation I spotted the problem and corrected the code.  I had called the interrupt vector TIMER0_A1  VECTOR instead of the TIMER0_A0 VECTOR  that I was trying to use.  I'm not sure yet if this was a typo or a difference between this chip and the earlier '1232.   Either way I can now re-enable the serial interrupts and get on with debugging the rest of the code.

    Thank you for focussing my attention on what should have been obvious to me!  I hope you haven't spent too much time looking at this.

    Regards,

    Graham

  • On 1232 (or other 1x series devices), there was only one TimerA. So the vectors were named TIMERA0_VECTOR and TIMERA1_VECTOR. Now, with more than one TimerA per device, the names have changed to TIMERx_A0_VECTOR and TIMERx_A1_VECTOR. This can lead to confusion.

    The usage of the A0 and A1 vector is still the same. The timer itself hasn't changed internally..

**Attention** This is a public forum