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