Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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);

} }

«1

Answers

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    include <msp430g2231.h>

    int main() { continuepolling:; if (pollbit = set) { goto exitsection; } goto continuepolling; exitsection:; return 0; }

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    The above is a rough draft of how you do it in Borland Turbo C 2.01; Anyways, where it says pollbit and set you have to define that part yourself. The include should also have a #include.

  • 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.

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    Jesus Christ!hehe That was fast response time. Remember, it is just a rough draft however it is the proper way you do it in my favourite compiler. Thank you for replying 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;
    }
    
  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    Jesus Christ!hehe Well, I tried if it did not help. Anyways, this is only my first 3 months back programming since my college days 20 years ago or so. Cheers either way. Friends forever.

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    Jesus Christ!hehe I might not know C++, however, I do know PASCAL, COBOL, FORTRAN90, BASIC, ASSEMBLY once a long long eon many ancient times pass haha

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    I went to L.C.C.C. in 1990-1996, then I transferred over to Lafayette College for a summer semester in 1996 before I purchased Borland C++ 5.5.

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    Now a days I am retired happy to settle down doing Borland Turbo C 2.01 like you said Icepickle.

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    My major is 2 years of official college credit programming and 3 years of theology independently.

«1
Sign In or Register to comment.