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.

COMPILING FAILURE AT ISR FUNCTION

Other Parts Discussed in Thread: MSP430F5131

Hello ,

I'm using MSP430F5131 , my project is to output a 1 pulse per second through P2.4 by 12.8MHz external oscillator.

I have defined TD0CCR0=16000-1; (devided 12.8MHz by 8 ) . 

I have compiled the following code : 

#include <msp430.h>
#include <intrinsics.h>



unsigned int timerCount = 0;
int main(void) {


	WDTCTL = WDTPW | WDTHOLD;		// Stop watchdog timer
	P2OUT &= ~(BIT4); 			//preload 1pps to '0'


	// set I/O pins directions
	P1DIR |=BIT6+BIT7;                      //set p1.x to 11000000
	P2DIR |=BIT4;	                       // Set P2.4 to output direction
    PJDIR |=BIT0+BIT1+BIT3;                // set pj.x output 0000 1011
    P2SEL |= BIT4;							//select the option of using TD0.0 in pin 2.4
    P2IES |= BIT4;                        // high -> low is selected with IES.x = 1.
    P2IFG &= ~BIT4;                          // To prevent an immediate interrupt, clear the flag for
                                          // P1.3 before enabling the interrupt.
    P2IE |= BIT4;                          // Enable interrupts for P1.3

    // Configure XT1 (external oscillator)
    PJSEL |= BIT4+BIT5;						// port select for xt1
    UCSCTL6 &= ~(XT1OFF); 				    //xt1 is on
    UCSCTL3 = 0;                            // FLL REFERENCE CLOCK REFERENCE = XT1

    // configure TD0.0 to output of 1 pulse per second

    TD0CCR0=16000-1;                          // setting TAR count up value 16000 (12.8MHz / 8 = 1.6MHz , 1.6MHz / 100 = 16000 Hz) when 100 is passed means 1 second has passed as well
    //TD0CCR1= 								//DUTY CYCLE OF 50%
    //TD0CCTL1=CCIE + OUTMOD_7;                    //enabling interuption + RESET/SET OUTPUT MODE
    TD0CTL0 =MC_2+ID_3+TDSSEL_0+TAIE;                //defining timer d TD0.0 (P2.4)

    __enable_interrupt();


    for(;;){                      // main loop (looping forever)



    	//   EXTERNAL / INTERNAL SELECTION BY SW4

    	if ((P2IN & BIT2)==0){         //  INTERNAL MODE
    		PJOUT |=BIT3;              // sends '1' from pj.3 output to the multiplexer U4 (uses the internal 1pps)

    		//PULSE 1 : DESCRETE ON/OFF AND SWITCH ON/BAD/OFF

                     if ((P2IN & BIT0)==0 || (P1IN & BIT0)==0) {        //NORMAL SIGNAL OF 1PPS checks if descrete source is on or 1pps sw pulse 1 is on
                    	 P1OUT |= BIT6; 									//ENABLES PULSE BY THE 'AND' GATE
                    	 PJOUT |= BIT0;				//ENABLES TTL TO RS232 CONVERTER (FOR DIFF OUTPUT)
			#pragma vector = TIMER0_D0_VECTOR
                    	 __interrupt void TIMER0_D0_ISR(void){
                	   if (++timerCount > 50) {  	// checks if the incrementation of timerCount reaches 50 (means 0.5 second has passed)
										   P2OUT ^=BIT4;               //generates 1pps out of p2.4
										   timerCount = 0;             // resets the timer count
										   }
										   P2IFG &=˜BIT4;             // clears the fl

                	 }
                   }
                     else {
                    	 P1OUT |= ~BIT6; 								//DISABLES PULSE BY SENDING A '0' TO THE AND GATE
                     }

and it alerts of failures : 

1) in the #pragma line it says : pragma vector can only be applied to a function definition , not "TIMER_D0_IS".

2) in this line :  P2IFG &=˜BIT4; , it says unrecognized token.

3) in the line __interrupt void TIMER0_D0_ISR (void){ says that he is expected a ";".

 

can someone help me figure out the compiler errors and fix them. 

thanks in advance

  • Hi Omer!

    It would be easier if you would use the Syntaxhighlighter for posting code:

    #include <msp430.h>
    #include <intrinsics.h>
    
    unsigned int timerCount = 0;
    
    int main( void )
    {
      WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
      P2OUT &= ~(BIT4); // preload 1pps to '0'
    
      // set I/O pins directions
      P1DIR |=BIT6+BIT7; //set p1.x to 11000000
      P2DIR |=BIT4;	// Set P2.4 to output direction
      PJDIR |=BIT0+BIT1+BIT3; // set pj.x output 0000 1011
      P2SEL |= BIT4; // select the option of using TD0.0 in pin 2.4
      P2IES |= BIT4; // high -> low is selected with IES.x = 1.
      P2IFG &= ~BIT4; // To prevent an immediate interrupt, clear the flag for P1.3 before enabling the interrupt.
      P2IE |= BIT4; // Enable interrupts for P1.3
    
      // Configure XT1 (external oscillator)
      PJSEL |= BIT4+BIT5; // port select for xt1
      UCSCTL6 &= ~(XT1OFF); //xt1 is on
      UCSCTL3 = 0; // FLL REFERENCE CLOCK REFERENCE = XT1
    
      // configure TD0.0 to output of 1 pulse per second
      TD0CCR0=16000-1; // setting TAR count up value 16000 (12.8MHz / 8 = 1.6MHz , 1.6MHz / 100 = 16000 Hz) when 100 is passed means 1 second has passed as well
      //TD0CCR1= 								//DUTY CYCLE OF 50%
      //TD0CCTL1=CCIE + OUTMOD_7;                    //enabling interuption + RESET/SET OUTPUT MODE
      TD0CTL0 =MC_2+ID_3+TDSSEL_0+TAIE;                //defining timer d TD0.0 (P2.4)
    
      __enable_interrupt();
    
      for(;;)
      {                     // main loop (looping forever)
        //   EXTERNAL / INTERNAL SELECTION BY SW4
        if ((P2IN & BIT2)==0) //  INTERNAL MODE
        {
          PJOUT |=BIT3; // sends '1' from pj.3 output to the multiplexer U4 (uses the internal 1pps)
    
          //PULSE 1 : DESCRETE ON/OFF AND SWITCH ON/BAD/OFF
    
          if ((P2IN & BIT0)==0 || (P1IN & BIT0)==0) // NORMAL SIGNAL OF 1PPS checks if descrete source is on or 1pps sw pulse 1 is on
          {
            P1OUT |= BIT6; //ENABLES PULSE BY THE 'AND' GATE
            PJOUT |= BIT0; //ENABLES TTL TO RS232 CONVERTER (FOR DIFF OUTPUT)
    			
            #pragma vector = TIMER0_D0_VECTOR
            __interrupt void TIMER0_D0_ISR(void)
            {
              if (++timerCount > 50) // checks if the incrementation of timerCount reaches 50 (means 0.5 second has passed)
              { 
                P2OUT ^=BIT4; // generates 1pps out of p2.4
                timerCount = 0; // resets the timer count
              }
    
              P2IFG &=˜BIT4; // clears the fl
            }
          }
          else
          {
            P1OUT |= ~BIT6; //DISABLES PULSE BY SENDING A '0' TO THE AND GATE
          }

    Now you can easily see that there is missing something. And you cannot put your interrupt function inside of your code.

    #include <msp430.h>
    #include <intrinsics.h>
    
    unsigned int timerCount = 0;
    
    int main( void )
    {
      WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
      P2OUT &= ~(BIT4); // preload 1pps to '0'
    
      // set I/O pins directions
      P1DIR |=BIT6+BIT7; //set p1.x to 11000000
      P2DIR |=BIT4;	// Set P2.4 to output direction
      PJDIR |=BIT0+BIT1+BIT3; // set pj.x output 0000 1011
      P2SEL |= BIT4; // select the option of using TD0.0 in pin 2.4
      P2IES |= BIT4; // high -> low is selected with IES.x = 1.
      P2IFG &= ~BIT4; // To prevent an immediate interrupt, clear the flag for P1.3 before enabling the interrupt.
      P2IE |= BIT4; // Enable interrupts for P1.3
    
      // Configure XT1 (external oscillator)
      PJSEL |= BIT4+BIT5; // port select for xt1
      UCSCTL6 &= ~(XT1OFF); //xt1 is on
      UCSCTL3 = 0; // FLL REFERENCE CLOCK REFERENCE = XT1
    
      // configure TD0.0 to output of 1 pulse per second
      TD0CCR0=16000-1; // setting TAR count up value 16000 (12.8MHz / 8 = 1.6MHz , 1.6MHz / 100 = 16000 Hz) when 100 is passed means 1 second has passed as well
      //TD0CCR1= 								//DUTY CYCLE OF 50%
      //TD0CCTL1=CCIE + OUTMOD_7;                    //enabling interuption + RESET/SET OUTPUT MODE
      TD0CTL0 =MC_2+ID_3+TDSSEL_0+TAIE;                //defining timer d TD0.0 (P2.4)
    
      __enable_interrupt();
    
      for(;;)
      {                     // main loop (looping forever)
        //   EXTERNAL / INTERNAL SELECTION BY SW4
        if ((P2IN & BIT2)==0) //  INTERNAL MODE
        {
          PJOUT |=BIT3; // sends '1' from pj.3 output to the multiplexer U4 (uses the internal 1pps)
    
          //PULSE 1 : DESCRETE ON/OFF AND SWITCH ON/BAD/OFF
    
          if ((P2IN & BIT0)==0 || (P1IN & BIT0)==0) // NORMAL SIGNAL OF 1PPS checks if descrete source is on or 1pps sw pulse 1 is on
          {
            P1OUT |= BIT6; //ENABLES PULSE BY THE 'AND' GATE
            PJOUT |= BIT0; //ENABLES TTL TO RS232 CONVERTER (FOR DIFF OUTPUT)
          }
          else
          {
            P1OUT |= ~BIT6; //DISABLES PULSE BY SENDING A '0' TO THE AND GATE
          }
        }
      }
    }
    
    #pragma vector = TIMER0_D0_VECTOR
    __interrupt void TIMER0_D0_ISR(void)
    {
      if (++timerCount > 50) // checks if the incrementation of timerCount reaches 50 (means 0.5 second has passed)
      {
         P2OUT ^=BIT4; // generates 1pps out of p2.4
         timerCount = 0; // resets the timer count
      }
    
      P2IFG &=˜BIT4; // clears the fl
    }

    And look at the last statement - there is a wrong symbol before BIT4 - it does not seem to be a "~".

  • ok i understand , but what if i want to generate the pulse (from the ISR) from a specific 'if' condition?
    How does the program know that the #pragma function that generates the pulse related to that if condition?
  • An interrupt function is not meant to be called by software, you could call any function doing the same instead, so why using interrupts at all?
  • coz i want to track the counter and use that flag when the 1 second has passed . so if i want to associate an interupt function to a specific condition , how do i do that? what happens if i get more than one condition , how do i use it in that case?
  • Please describe your idea of the code in detail - what do want to do?
  • Ok let me explain what i want exactly :

    My main goal is to generate a 1 pulse per second using a duty cycle of 50% by a 12.8MHz external oscillator.

    I already have a printed PCB for that project which means i got to understand what the previous designer had done and implement it into my CCS program in order to program my micro controller.

    i am still new to this whole microcontroller world and im eager to know more , although im short in time.

    I have attached an electrical wiring of the PCB to help you understand a little bit more about the project.

    A little explanation of the electrical wiring:

    An external toggle switch (from connector J6 "Internal/External Selection") switch between an external 1pps (From an external GPS) or internal 1pps (by the msp430).

    if we choose an internal mode then (input P2.2) a '1' (or '0' if its an active low mode which is an active low mode) sends from PJ.3 (ouput) to U4 and a 1 pulse per second gets out of P2.4 output to connectors J8 and J9 (same pulse different connectors).

    I can Switch signals to ON/BAD/OFF by using an external toggle switch(pins 1,2 of J3 connector) or a descrete (pin 3 of J3 connector).

    if i toggle the switch to on mode it sends '1'(or '0' if its an active low mode which is an active low mode) through P1.6 to U5 ( And Gate) and enables the pulse it also sends '1' through PJ.0 to U6 and converts the pulse from TTL to RS422 (differetial).

    The descrete switching option switches the pulse (ON/OFF) the same as the external toggle switch.

    This is refers to PULSE 1 , i need to implement the same thing for PULSE 2.

    although im still not sure what RST/NMI/SBWTDIO and TEST/SBWTCK are wired for , are these for downloading the program into the msp?

    im also not sure about the PJ.2 pin (FUNCTIONALITY DISABLE).

    PCB electrical wiring.pdf

**Attention** This is a public forum