cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with pow() function in CubeMX project

starcu93
Associate
Posted on June 20, 2016 at 08:59

Hello,

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 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. Greetings. #disco #eclipse #stm32cubemx
1 REPLY 1
slimen
Senior
Posted on June 28, 2016 at 12:30

Hi,

About your second problem: I Suggest you download and review some of examples which presented in the STM32cubeF0 firmware.

You can start from an example under the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef0.html

package, you find the needed include parts for your project.

You can take an example as start point to make required updates and refer to this 

http://www.st.com/content/ccc/resource/technical/document/user_manual/e1/57/ec/f2/81/31/46/76/DM00119724.pdf/files/DM00119724.pdf/jcr:content/translations/en.DM00119724.pdf

manual : ''Getting started with STM32CubeF0 for STM32F0 Series''

Regards