1
votes

I have a codebase that compiles for both a PIC18 and PIC24.

Whilst writing a driver for a new sensor on the PIC24, I recompiled for the PIC18 and the calculation of pressure fails:

{
    // Normal operation, valid data
    uint32_t rawPressure = ((ssc_sr_1[0] & 0x3F) << 8) + ssc_sr_2[0];
    filter_pressure_left = (uint16_t)(MIN_PRESSURE_PA + (rawPressure - MIN_PRESSURE_RAW)*(MAX_PRESSURE_PA-MIN_PRESSURE_PA)/(MAX_PRESSURE_RAW-MIN_PRESSURE_RAW));
}

On compile, the error i2c.c:546: error: (195) expression syntax (where line 546 is the filter_pressure_left = line) is thrown.

I cannot see anything syntactically wrong to throw this error, which is backed up by it not being thrown when compiling with xc16-gcc.

Compiler Versions:

  • XC16-GCC V1.23
  • XC8 V1.33

Additional information requested surrounding values used:

DECLARE unsigned char ssc_sr_1[2];
DECLARE unsigned char ssc_sr_2[2];
#define MAX_PRESSURE_PA                 249
#define MIN_PRESSURE_PA                 -249
#define MAX_PRESSURE_RAW                14745   // 90% of 2^14
#define MIN_PRESSURE_RAW                1638    // 10% of 2^14
1
what is the expected value and what was returned?phuclv
Compiler message is the title of this question "Error: (195) expression syntax" and occurs on the second line. It is not an issue of wrong value returned, it is that the compiler will not accept that line - I included the line before due to previous questions asked about the error actually stem from missing semi-colons on the line before etc.M Curry
I presume ssc_sr_1 is uint8_t or other 8-bit value? If not, potentially the compiler could be detecting an invalid operation.Neil
Probably one of the compilers can't find the stdint.h types. Did you include that header and do both compilers support C99? Are both compilers configured to compile as C99?Lundin
With the filter_pressure_left = line commented out, the code compiles, so it shouldn't be a stdint issue.M Curry

1 Answers

2
votes

Spaces spaces spaces!

Changing the second line to:

filter_pressure_left = (uint16_t)(MIN_PRESSURE_PA + (rawPressure - MIN_PRESSURE_RAW) * (MAX_PRESSURE_PA - MIN_PRESSURE_PA) / (MAX_PRESSURE_RAW - MIN_PRESSURE_RAW));

compiles without error.

For reference to people coming across this in the future - split your equation to multiple lines to identify exactly which portion is failing - in my case (MAX_PRESSURE_PA-MIN_PRESSURE_PA) caused the error and absent-mindedly adding spaces and re-compiling cured it.