Code crashing? PC 13 flashing with wire lib

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

Code crashing? PC 13 flashing with wire lib

Post 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);
}
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Code crashing? PC 13 flashing with wire lib

Post 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.
dingexamine
Posts: 1
Joined: Mon Apr 10, 2023 6:56 am

Re: Code crashing? PC 13 flashing with wire lib

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

Return to “General discussion”