2023-11-12 05:53 PM
Hi, I'm using an STM32F401RE board for a class(programming using MacOS). Right now, I'm using VSCode and make to edit and compile my code, then using stlink to flash it. Now, I'm trying to communicate with an MPU6050 using I2C; however, when I run HAL_I2C_IsDeviceReady() all I'm getting is a return of HAL_BUSY. This happens even when everything is unplugged. Everything should be wired correctly, I've double checked and the green light on the MPU6050 lights up.
Here is my code:
2023-11-13 03:25 AM
Hello @AllanLiu ,
Could you please check the initialization and the configuration of the I2C bus and try to check the HW connection.
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-11-13 06:20 AM
Are the required pull-up resistors installed for both the SCL and SDA signals?
What's the value of "MPU6050_ADDR"?
2023-11-13 10:06 AM
I figured it out. Turns out when I was soldering the board I missed the SDA pin, so I was getting that error.
Now however, I'm getting funny values from the sensor, even though I'm dividing by 131.0 like the datasheet says. I've attached my code below if anyone would like to help me out 🙂
2023-11-13 10:25 AM
In readGyroGx() maybe gxh and gxl should be 8-bit variables?
2023-11-13 10:27 AM
I started with trying uint8_t datatype for gxh and gxl but it has the same outputs as using int.
2023-11-13 10:43 AM - edited 2023-11-13 12:38 PM
Well, then, it's back to the Data Sheet! 😀
2023-11-13 10:54 AM
Well, to be more clear it Gx rests at roughly 46 but as soon as I rotate the mpu6050 Gx changes to a more reasonable value close to 0 because I was rotating it slowly.
2023-11-13 02:18 PM - edited 2023-11-13 02:19 PM
uint8_t gyroData[] = {0};
uint8_t gyroRegAddrStart = 0x43;
HAL_StatusTypeDef pass;
for (int i = 0; i < 6; i++) {
pass = HAL_I2C_Mem_Read(&hi2c1, MPU6050_ADDR, gyroRegAddrStart + i, 1, &gyroData[i], 1, 100);
Here is your bug. There are no gyroData[i] elements besides of i==0. Recommendation as usual: get a good static analyzer. Consider changing the code:
uint8_t gyroData[6] = {0};
uint8_t gyroRegAddrStart = 0x43;
HAL_StatusTypeDef pass;
pass = HAL_I2C_Mem_Read(&hi2c1, MPU6050_ADDR, gyroRegAddrStart, 1, gyroData, 6, 100);