cancel
Showing results for 
Search instead for 
Did you mean: 

How to use HAL i2c and math.h in same project?

MDoğr.1
Associate II

Hi everyone! I am using STM32F4 and IMU to read gyro and accelerometer, and than calculate IMU's euler angles. I can get data from IMU it is OK but when I try to add something from math.h program stops working but it also don't gives error or warninng -I can't even read acceleration and gyro data in STM Studio-. I need to use sqrtf() and acosf() functions. I think I am using math.h library in wrong way. Here is my codes math.h related parts:

#include <math.h>

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

G_Read(0x18, 6);

 // (msb<<8) | lsb

 gx= (Gyro[1]<<8)| Gyro[0];

 gy= (Gyro[3]<<8)| Gyro[2];

 gz= (Gyro[5]<<8)| Gyro[4];

 A_Read(0x28, 6);

 ax=(Accel[1]<<8)| Accel[0];

 ay=(Accel[3]<<8)| Accel[2];

 az=(Accel[5]<<8)| Accel[4];

 HAL_Delay(30);

 grx= gx*(245.0/32768.0);

 gry= gy*(245.0/32768.0);

 grz= gz*(245.0/32768.0);

 arx=ax*(2.0/32768.0);

 ary=ay*(2.0/32768.0);

 arz=az*(2.0/32768.0);

 grx=grx-1.12;

 gry=gry-0.63;

 grz=grz+1.23;

 HAL_Delay(30);

 R=arx*arx+ary*ary+arz*arz;

//if I make bottom part comment program works as it will but if I don't it don't :(

R=sqrtf(R);

 HAL_Delay(30);

 aanx= acosf(arx/R);

 aany= acosf(ary/R);

 aanz= acosf(arz/R);

 HAL_Delay(30);

 }

Here is the results with math.h and without math.h:

0693W000004JjWRQA0.png0693W000004JjZ5QAK.png

1 ACCEPTED SOLUTION

Accepted Solutions
MDoğr.1
Associate II

I changed pins pb7 pb6 to pb9 pb8 and it started to work welll

View solution in original post

1 REPLY 1
MDoğr.1
Associate II

I changed pins pb7 pb6 to pb9 pb8 and it started to work welll