This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Syntax errors only when adding UART connection

Hi all,

I'm brand new at this. I'm in microVision coding for an ADuC7026 eval board from Analog. I have some preexisting code that works fine. However, I need to add a UART interface to this. Pulling the block of lines right out of a working (and tested) example from the manufacturer, I place it into my code (at the beginning of my main function, as it is in the example). I copy the entire routine for Setting up the correct tx/rx pins and just initializing the UART connection. Taking a UART example that includes a printf hello world function, the code does not compile. I end up with syntax errors marked starting at the preexisting code (what comes right after what I've inserted). I end up with the following errors all over the place:

CAVITY.C(47): error C25: syntax error near 'unsigned'
CAVITY.C(54): error C25: syntax error near 'volatile'
CAVITY.C(54): error C25: syntax error near ')'

And so on. I have no idea what this is trying to tell me. The string 'volatile' isn't even in my code. This just won't work. This is the code I've inserted:

// Setup tx & rx pins on P1.0 and P1.1
GP1CON = 0x011;
// Start setting up UART at 9600bps
COMCON0 = 0x080;// Setting DLAB
COMDIV0 = 0x088;// Setting DIV0 and DIV1
COMDIV1 = 0x000;
COMCON0 = 0x007;// Clearing DLAB

GP4DAT = 0x04000000;
printf ("Hello World\n");

Again, this is taken straight from a working example. Any insight would be GREATLY appreciated. Thanks.

Parents
  • Can you show the source code lines around the error message, and point out line 47 or 54.

    Do you have any conditional compilations?

    Might you have a text sting that is missing the termination quotation?

    Might there be an expression with a missing parenthesis?

    Or a statement block with nesting errors of braces?

    One thing you can do is request that the compiler generates an output file after running the preprocessor. In case a define results in stupid code replacement, the preprocessed source - when compiled - will clearly show exactly what the compiler saw.

Reply
  • Can you show the source code lines around the error message, and point out line 47 or 54.

    Do you have any conditional compilations?

    Might you have a text sting that is missing the termination quotation?

    Might there be an expression with a missing parenthesis?

    Or a statement block with nesting errors of braces?

    One thing you can do is request that the compiler generates an output file after running the preprocessor. In case a define results in stupid code replacement, the preprocessed source - when compiled - will clearly show exactly what the compiler saw.

Children
  • Thanks for all your help, by the way. I had to wait until today to get into the lab to get the code. Here's my code with comments where those errors (which are a very small sampling of the errors) occurred:

    int main (void)  {
    
    ///TESTING UART CONNECTION///
    
    // Setup tx & rx pins on P1.0 and P1.1
    GP1CON = 0x011;
    
    // Start setting up UART at 9600bps
    COMCON0 = 0x080;// Setting DLAB
    COMDIV0 = 0x088;// Setting DIV0 and DIV1
    COMDIV1 = 0x000;
    COMCON0 = 0x007;// Clearing DLAB
    
    GP4DAT = 0x04000000;// P4.2 configured as an output.
    printf ("Hello World\n");// printf function call
    
    //END UART TESTING//
    
    // Table is placed in Flash/EE;
    unsigned short TableS1[N]; //This is "line 47"
    unsigned short TableS2[N];
    
    float   i = 0;
    int     j = 0, k = 0, l=0;
    int     n1=R1/R2, r1delay=0;
    
    GP2DAT= Pn2Off;//Error signal//This is "line 54"
    GP1DAT= Pn2On;//Modulation
    
    

    I reach syntax errors "near" both of these lines and continuing down the rest of my code. These errors don't exist when I try to compile without the UART configuration block of code. If I try to just comment out line 47, I end up with the same error at line 48.

    I've played with my code a lot to try to find an actual syntax error, but I can't find a thing. It just doesn't make sense to me that it would compile without the inserted code, but hates me when I do add it. I'm not that experienced with C, so maybe I'm making a silly mistake?

    I couldn't find a way to make uVision produce a preprocessed output. Any hints?

    Thanks.
    -Larry

  • You didn't show the definition of N. Is it a preprocessor define? Might you have a comma or other extra character around the defined value?

  • N is defined in a header. But if there were a problem in the header file, wouldn't that cause it to not compile even if I didn't insert that block of code?

  • I got the code to compile by moving the code block slightly down. Somehow, this allowed it to compile. Thanks for all your help!

  • It was to obvious to be visible :)

    When compiling C programs, you have to have all variable declarations before the code statements.

  • Ah okay. I didn't know they all had to be declared first. Thanks!