Page 1 of 1

code crashing?, PC13 flashing? i2c

Posted: Sun Jul 12, 2020 10:08 am
by georgesshed
Hi all,

Im trying to use an mpu6050 with the stm32 duino.

It seems to work initially but after a random amount of time (5-15 seconds) the serial output stops and PC13 led starts flashing?

i cant find reference to this issue sanywhere and dont know what is wrong as it works for a bit?

Code: Select all

#include<Wire.h>
 
const int MPU_addr=0x68;

int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
 
int minVal=265;
int maxVal=402;
 
double x;
double y;
double z;
 
void setup(){
Wire.begin();
//Wire.setClock(400000);
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true);

AcX=Wire.read()<<8|Wire.read();
AcY=Wire.read()<<8|Wire.read();
AcZ=Wire.read()<<8|Wire.read();

int xAng = map(AcX,minVal,maxVal,-90,90);
int yAng = map(AcY,minVal,maxVal,-90,90);
int zAng = map(AcZ,minVal,maxVal,-90,90);
 
x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);
y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);
z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);
 
Serial.print("AngleX= ");
Serial.println(x);
 
//Serial.print("  AngleY= ");
//Serial.println(y);
// 
//Serial.print("AngleZ= ");
//Serial.println(z);
//Serial.println("-----------------------------------------");
delay(100);
}

Re: code crashing?, PC13 flashing? i2c

Posted: Sun Jul 12, 2020 7:17 pm
by dannyf
comment out certain sections of the code and see if you still have the problem.

and gradually narrow down the possible cause.

Re: code crashing?, PC13 flashing? i2c

Posted: Sun Jul 12, 2020 7:41 pm
by fredbox
I had a board like that a couple of years ago. It turned out that I had let the magic smoke out of diode D1 that fed power to the board from the USB connector. If you have another source of 3.3 volts (st-link, usb/serial adapter) you might try powering the board through a different source and see if the problem clears.

Re: code crashing?, PC13 flashing? i2c

Posted: Wed Jul 15, 2020 4:24 pm
by georgesshed
dannyf wrote: Sun Jul 12, 2020 7:17 pm comment out certain sections of the code and see if you still have the problem.

and gradually narrow down the possible cause.
Thanks danny, I tried that and it only went when i removed the i2c library completley.

Re: code crashing?, PC13 flashing? i2c

Posted: Thu Jul 16, 2020 7:10 am
by stevestrong
Does the i2c scanner example work?

Re: code crashing?, PC13 flashing? i2c

Posted: Thu Jul 16, 2020 8:33 am
by fpiSTM
Which core and board you used ?
I guess the BluePill with the maple bootloader.
If true, I think your board crash and restart in BL mode that's why you see the LED blink.

Re: code crashing?, PC13 flashing? i2c

Posted: Tue Aug 11, 2020 12:27 pm
by santhit@hotmail.com
Me too. Your problem was like mine. Serial stop sending data. The serial moniter freeze after 10 seconds. When I change to arduino uno board is not freeze. May be it concerns with not enough energy.

Re: code crashing?, PC13 flashing? i2c

Posted: Tue Apr 02, 2024 4:02 pm
by Lucas Cartaman
I also had the same problem, with exactly the same hardware (Blue Pill STM32F103C8T6 and an MPU6050).

If it is connected to the I2C1 port it works correctly with the Wire.h library, when connected to the I2C2 port (PB11 - SDA and PB10 - SCL) and using TwoWire the code crashes after a few seconds and the PC13 LED flashes, and when it crashes the outputs maintain their last state.

THE SOLUTION

With this code Blue Pill crashes

Code: Select all

#include <Wire.h>
TwoWire HWire (2, I2C_FAST_MODE);  
If I replace it with this library it works correctly

Code: Select all

#include <SoftWire.h>
SoftWire HWire(PB10, PB11, I2C_FAST_MODE);
I hope it works for you too.

On the other hand, I wanted to ask a question.

I'm testing a flight controller software for a drone and the fact that the blue pill maintain his output state when it crashes scares me. If the crash happens while I am flying the drone I will lose control and will not be able to press the reset button on the BluePill, but the motors will not stop and the drone will continue flying without being able to stop it.

Is there a way to make sure that if the BluePill crashes, it turns off all its outputs instead of keeping them active?