Page 1 of 1

Code crashing? PC 13 flashing with wire lib

Posted: Sat Jul 11, 2020 6:42 pm
by georgesshed
Hi all,

Im trying to use an mpu6050 with the stm32 duino.

It seems to for 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? PC 13 flashing with wire lib

Posted: Mon Jul 13, 2020 8:08 am
by fpiSTM
You request 14 bytes and read only 6 ?

You said the LED is blinking?
ON which board? it seems strange as no handler use the LED by default and your code doesn't seem to mange the LED.

Re: Code crashing? PC 13 flashing with wire lib

Posted: Mon Apr 10, 2023 6:58 am
by dingexamine
It seems to function well, however after some arbitrary period of time (between 5 and 15 seconds), the serial output ceases and the PC13 led begins blinking. As it seems to function for a while, but then stops, I can't seem to locate any mention of this problem anywhere.