I am currently working on a quadrocopter project. I started it with and Arduino Board, but since of the higher speed I moved to this board.
I managed to uplaoad sketches and everything seems to work pretty solid so far.
Now I want to import my sketch to this board starting with the IMU (6050) which is controlled by i2c.
I used this https://developer.mbed.org/users/hudakz … 8T6_Hello/ as a reference for the pinouts.
There I got the first problems:
– There are two I2c1 ports? working with the first one (PB_9 and 8 ) was pretty slow.
Why is this?
-Can I use I2C the same way I do on an Arduino board or do I have to consider certain things?
Thank you for your support!
helpful information on wiki http://wiki.stm32duino.com/index.php?title=Main_Page
mbed != Arduino_STM32; more correctly imho mbed <<<<< Arduino_STM32
speed, no idea other than maybe mbed
btw
pb6 pb7 are i2c1.
pb8 pb9 are i2c2.
srp
I will click thorugh the wiki and propably come back with a few more questions
~/sketchbook/hardware/Arduino_STM32/STM32F1/libraries/Wireit seemed mbed bundles a keil rtos
https://github.com/ARMmbed/mbed-os
taking a look at the api codes, i think it probably may not be ‘arduino compatible’
i’m not too sure if it is possible to simply build mbed using the arm-gcc toolchain. apparently mbed readme specifically states
Getting Started for Developers
You need mbed CLI to build mbed OS. For more details, read the mbed OS Handbook.
there are some specific mentions of an ‘mbed firmware’
https://developer.mbed.org/cookbook/ecl … -debugging
i’m not too sure if that means certain things would only be distributed as binary blobs on the devices
Hardware I2C should now be working Ok, and will be faster, but you will need to instantiate an instance of the hardware I2C class to use it.
Search the forum, there are many posts about using hardware I2C
Note. The reason that I have not switched to the core using Hardware I2C by default, is that the speed of software i2C is enough for most people and I think is at least equivalent to the AVR boards.
Software I2C can run on any pin.
Software I2C has been tested and used by loads of people and is stable.
Hardware I2C now works, but is not extensively tested.
I got one more question: is it possible, that conversion from bytes to float/int is different on the stm board?
This is the code I am talking about:
//Reading Raw:
Wire.beginTransmission(this->Adress);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission();
Wire.requestFrom(this->Adress,14); // request a total of 14 registers
this->x_accel=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
this->y_accel=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
this->z_accel=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Serial.print(" ax: "); Serial.print(this->x_accel);
Serial.print(" ay: "); Serial.print(this->y_accel);
Serial.print(" az: "); Serial.print(this->z_accel);
this->x_accel=(float)this->x_accel*this->AccelMultipl/32767*this->correction[0] + this->bias[0];
this->y_accel=(float)this->y_accel*this->AccelMultipl/32767*this->correction[1] + this->bias[1];
this->z_accel=(float)this->z_accel*this->AccelMultipl/32767*this->correction[2] + this->bias[2];
The “int” data type on STM32 is 32 bits, but on AVR its only 16 bits
So your maths that has the value 32768 will not work on the STM32 unless you change the data type of your X Y and Z struct values to be 16 bit ints rather than 32 bit.
try using
int16_t
as the data type in that struct
Edit: found a workaround thank you so much! Woul have taken me ages to find all that
How do I change the pins used by the standard Wire library?
I tried:
Wire=TwoWire(PB5,PB4);
this->Adress=Adress;
Wire.begin();
Wire.beginTransmission(Adress);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission();
Wire.beginTransmission(Adress);
Wire.write(0x1A); // CONFIG register
byte val=B00000110; //
Wire.write(val); // Set the LowPassFilter
Wire.endTransmission();
Only by uploading over STM32duino bootloader, PB4 can be used as GPIO, and thus for I2C, too.
Otherwise you have to manually edit boards.txt and remove “-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1” from the respective lines.
Search the forum for PB4…
I just found this viewtopic.php?f=3&t=2084&p=27945&hilit=PB4#p27945
and the line disableDebugPorts(); resolves my issue!
Damn thanks!!

![[SOLVED] Discovery STM32F100RB — Trouble with timers and library structure](https://sparklogic.ru/wp-content/uploads/2019/11/st-stm32vl-discovery-90x90.jpg)
