code crashing?, PC13 flashing? i2c

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
georgesshed
Posts: 6
Joined: Mon May 18, 2020 5:17 pm

code crashing?, PC13 flashing? i2c

Post 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);
}
dannyf
Posts: 447
Joined: Sat Jul 04, 2020 7:46 pm

Re: code crashing?, PC13 flashing? i2c

Post by dannyf »

comment out certain sections of the code and see if you still have the problem.

and gradually narrow down the possible cause.
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: code crashing?, PC13 flashing? i2c

Post 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.
georgesshed
Posts: 6
Joined: Mon May 18, 2020 5:17 pm

Re: code crashing?, PC13 flashing? i2c

Post 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.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: code crashing?, PC13 flashing? i2c

Post by stevestrong »

Does the i2c scanner example work?
User avatar
fpiSTM
Posts: 1754
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: code crashing?, PC13 flashing? i2c

Post 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.
santhit@hotmail.com
Posts: 1
Joined: Sat Dec 21, 2019 11:02 pm

Re: code crashing?, PC13 flashing? i2c

Post 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.
Lucas Cartaman
Posts: 3
Joined: Mon Oct 30, 2023 1:32 am
Location: Paraguay

Re: code crashing?, PC13 flashing? i2c

Post 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?
Post Reply

Return to “General discussion”