Why am I getting this errror message "expected an identifier" ?? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Why am I getting this errror message "expected an identifier" ??

SD_new_guySD_new_guy United StatesPosts: 1Member

Am using the MSP430 Microcontroller, the IAR compiler (free version). Am trying to get the program to execute a loop while it's polling a bit, and exit the loop as soon as the bit (USIIFG flag) is set.
At first the program would pass right over the loop and immediately execute the code after the loop :(
I thought it may be because, in that version of the program, the USSIFG flag was not properly declared as “volatile to prevent optimization”. So I declared it. That’s when the new error message “expected an identifier” showed up. It’s on the line where the USIIFG flag is declared at the top of the code*.

This is one of my first C programs, and I really don’t know what I’m doing.

All this program is supposed to do is transmit 16 bits over the SPI port, wait till the CPU clocks out the data, then continue to a short delay, and repeat. Everything works except the loop which waits for USIIFG to go high, before continuing.
What am I doing wrong in my attempt to poll that bit?

include "msp430g2231.h"

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction

for (;;)

{
volatile unsigned int i; // volatile to prevent optimization
volatile unsigned int USISR; // volatile to prevent optimization
*volatile unsigned int USIIFG; // volatile to prevent optimization
#define RSTSENSOR 0xAAAA;
#define RSTSENSOR1 0x00;
j = 0;
USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI master
USICTL1 |= USIIE; // Counter interrupt, flag remains set
USICKCTL = USIDIV_4 + USISSEL_2; // /16 SMCLK
USICTL0 &= ~USISWRST; // USI released for operation.
__intrinsic unsigned long __data16_read_USISR (unsigned short __addr);
// Read USISR Before writing to it.
USISR = RSTSENSOR; // init-load data

{
goto TEST;
LOOPSTART:
TEST:
if (USIIFG == 0) goto LOOPSTART;
}

i = 40; // SW Delay
do i--;
while (i != 0);

}
}

Answers

  • SD_new_guySD_new_guy United StatesPosts: 1Member

    Thanks tienkhoanguyen.
    I am new to the site. Apparently the site deletes all the carrige returns, making it almost impossible to decifer some code posts. I'll have a go at what you sent me and see how it goes.
    Thanks again.
    Darren.

  • IcepickleIcepickle GermanyPosts: 49Member

    as far as i can use the "quote" button, the original code would be

    #include "msp430g2231.h"
    
    int main(void)
    {
     WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
     P1DIR |= 0x01;                                // Set P1.0 to output direction
    
     for (;;)
     {
       volatile unsigned int i;                 // volatile to prevent optimization
       volatile unsigned int USISR;             // volatile to prevent optimization
       *volatile unsigned int USIIFG;                // volatile to prevent optimization
       #define RSTSENSOR 0xAAAA;
       #define RSTSENSOR1 0x00;
       j = 0;
       USICTL0 |= USIPE7 +  USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI master
       USICTL1 |= USIIE;                          // Counter interrupt, flag remains set
       USICKCTL = USIDIV_4 + USISSEL_2;      // /16 SMCLK
       USICTL0 &= ~USISWRST;                 // USI released for operation.
       __intrinsic unsigned long  __data16_read_USISR (unsigned short __addr);
                                                    // Read USISR Before writing to it.
       USISR = RSTSENSOR;                       // init-load data
    
       {
            goto TEST;
            LOOPSTART:
            TEST: 
            if (USIIFG == 0) goto LOOPSTART;
       }
    
    
       i = 40;                       // SW Delay
       do i--;        
       while (i != 0);      
    
       }
    }
    

    now, the trick to inserting code as code blocks, is first leaving an empty line, and then start every new line with 4 spaces

    tienkhoanguyen said:

    #include <msp430g2231.h>
    
    int main()
    {
        continuepolling:;
        if (pollbit = set)
        {
            goto exitsection;
        }
        goto continuepolling;
        exitsection:;
        return 0;
    }
    
Sign In or Register to comment.