Page 1 of 1

problem with proper i2c operation on STM32F411CEU6 (blackpill)

Posted: Sat Aug 31, 2024 12:42 pm
by qubalab
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:

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
}

Re: problem with proper i2c operation on STM32F411CEU6 (blackpill)

Posted: Sat Aug 31, 2024 12:46 pm
by qubalab
ADDITIONAL INFO: the mpu6050 was tested on arduino nano, and worked just fine, basic code with printing out text or blinking was executed by mentioned board (the title is kinda wrong, blackpill is not the STMF4..., but you know what do I mean).

Re: problem with proper i2c operation on STM32F411CEU6 (blackpill)

Posted: Sat Aug 31, 2024 6:08 pm
by GonzoG
Look at the wire::begin() usage and what you have in your code:

Code: Select all

#include <Wire.h>
//            SDA  SCL
TwoWire Wire2(PB3, PB10);

void setup() {
  Wire2.begin(); 
}

void loop() {
  Wire2.beginTransmission(0x71);
  Wire2.write('v');
  Wire2.endTransmission();
  delay(1000);
}
example from: https://github.com/stm32duino/Arduino_C ... ki/API#i2C

Your code should not work properly even on Arduino board.

Re: problem with proper i2c operation on STM32F411CEU6 (blackpill)

Posted: Sun Sep 01, 2024 8:26 am
by qubalab
Thanks for your reply, well, I completely missed this docs :shock: