problem with proper i2c operation on STM32F411CEU6 (blackpill)
Posted: Sat Aug 31, 2024 12:42 pm
I have flashed a simple code on my blackpill (code below) and then connected my mpu6050 to it by plugging VCC => 3.3V, GND=>GND, SCL => PB6 and SDA => PB7. I've also plugged pullup resistors (tried with 4.7k ohm and 10k ohm) from VCC (on mpu6050) to PB6 and separately to PB7. At the end I have also connected 10k ohm resistor from pin PA10 to GND, because of problems with entering the DFU mode. My code's task is to print out non processed values of rotational speed from mpu6050. The problem is, it returns a constant value of -0.2 for all of its axis
. It seems just like it couldn't initialize the communication. mpu6050 register map: https://invensense.tdk.com/wp-content/u ... r-Map1.pdf
Sorry if I've missed something really obvious, any help would be appreciated. THE MENTIONED CODE:

Sorry if I've missed something really obvious, any help would be appreciated. THE MENTIONED CODE:
Code: Select all
#include <Wire.h>
float RateRoll, RatePitch, RateYaw;
void gyro_signals(void) {
Wire.beginTransmission(0x68);
Wire.write(0x1A);//accessing configuration (register 26)
Wire.write(0x05);//setting DLPF value to 5 (101)
Wire.endTransmission();
Wire.beginTransmission(0x68);
Wire.write(0x1B);//accessing gyroscope configuration (register 27)
Wire.write(0x8);//setting 'FS_SEL' value to 1
Wire.endTransmission();
Wire.beginTransmission(0x68);
Wire.write(0x43);//setting the first of gyroscopic mesurments register (register 67)
Wire.endTransmission();
Wire.requestFrom(0x68,6);//requesting 6 bytes from the one selected before
int16_t GyroX=Wire.read();//setting the values up
Wire.read();
int16_t GyroY=Wire.read();
Wire.read();
int16_t GyroZ=Wire.read();
Wire.read();
RateRoll=(float)GyroX/65.5;//caluclating designated values
RatePitch=(float)GyroY/65.5;
RateYaw=(float)GyroZ/65.5;
}
void setup() {
Serial.begin(57600);//initialization of serial communication
Wire.setClock(400000);//mathing 400kHz frequency of mpu6050
Wire.begin(PB6,PB7);
delay(250);//waiting for mpu6050 to turn on.
Wire.beginTransmission(0x68);
Wire.write(0x6B);//setting the power management 1 settings
Wire.write(0x00);// -||-
Wire.endTransmission();
}
void loop() {
gyro_signals();//function callout
Serial.print("Roll rate [°/s]= ");//printing the values
Serial.print(RateRoll);
Serial.print(" Pitch Rate [°/s]= ");
Serial.print(RatePitch);
Serial.print(" Yaw Rate [°/s]= ");
Serial.println(RateYaw);
delay(50);//for readability
}