AnsweredAssumed Answered

Problems with pow() function in CubeMX project

Question asked by es.lukasz on Jun 20, 2016
Latest reply on Jun 28, 2016 by ForumSTM32.ForumSTM3

I have wrote program to read data from ms5611 barometer for my F0Discovery board and i have two problems with it.

First I need to convert pressure read by uC into alitude. To read real altitude i using code shown below:

uint32_t ms5611RealPressure(I2C_HandleTypeDef *hi2c)
        uint32_t pressData = 0;
        uint32_t tempData = 0;
        int32_t realPress = 0;
        int32_t dT = 0;
        int32_t TEMP = 0;
        int64_t OFF = 0;
        int64_t SENS = 0;
        pressData = ms5611PresTempRead(hi2c, pressure, UHIGH); //odczyt cisnienia RAW
        tempData = ms5611PresTempRead(hi2c, temperature, UHIGH);
        dT = tempData - (promData[4] * pow(2,8));
        TEMP = 2000 + dT * (promData[5] / pow(2,23));
        OFF = (promData[1] *  pow(2,16)) + (promData[3] * dT) /  pow(2,7);
        SENS = (promData[0] *  pow(2,15)) + ((promData[2] * dT) /  pow(2,8));
        realPress = ((pressData * (SENS / pow(2,21))) - OFF) /  pow(2,15);
        return realPress;

and it's work fine.

For convert it to altitude i using function like this:
float ms5611Altitude(int32_t pressure)
    float sealevelPressure = 101325;
    float MS5611_ALT_Data;
    MS5611_ALT_Data = 44330 * (1.0 - pow((float)pressure / sealevelPressure, 0.1903));
    return MS5611_ALT_Data;

this function had worked in similar program wrote with StdPeriph, but now i getting compilation error when i want to pass my function pressure readings into altitude converion function. I passed ms5611RealPressure reading into variable and then into ms5611Altitude but it didn't help. When i put for example 56.453453 variable into pow function everything works fine. I have -lm included into my compilation command.

Error in Eclipse is just "make: *** [_F0ms5611read.elf] Error 1    _F0ms5611read             C/C++ Problem".

My second problem is I don't know how to create .h and .c file which can work in my program. When i created .h file (put into \_F0ms5611read\Drivers\STM32F0xx_HAL_Driver\Inc) and put variables and function definitions into it and then created .c file (put into \_F0ms5611read\Drivers\STM32F0xx_HAL_Driver\Src) with .h file included my program returned error that it can't find requested functions. I was trying to link .c file to WORKSPACE_LOC but then it was returned many errors for example "unknown type name uint32_t".

I'm new in C and STM32 programming and I don't know how to handle with these errors so please for help.