HWire.endTransmission

This first part of code works, even though the 6050 is not configured i can read it's id.

type or #include <SoftWire.h>
 #include <Wire.h>
 #include <SoftWire.h>
 #include <wire.h>
 TwoWire HWire (2,I2C_FAST_MODE);

 int8_t x=0;
 int8_t gyro_address = 0x68;

 void setup()

 {
 Serial2.begin(9600);
 delay(250);

 //gyro_setup();
  
 }
 
void loop()
 {
 HWire.begin();
 HWire.beginTransmission(gyro_address);
 HWire.write(0x43);
 HWire.endTransmission();
 HWire.requestFrom(gyro_address,1);
 x = HWire.read();
 Serial2.print(x);
 delay(5);

 } 

Notice gyro_setup is remmed out, so far so good. If i unrem it the program hangs at HWire.endTransmission in gyro_detup. If i rem out the 4 lines HWire.endTransmission the program runs but of course the 6050 is configured so i again can only read id.

gyro_setup, which is in file gyro.ino.

void gyro_setup(void)
  {
    
  HWire.beginTransmission(gyro_address);                        //Start communication with the MPU-6050.
  HWire.write(0x6B);                                         //We want to write to the PWR_MGMT_1 register (6B hex).
  HWire.write(0x00);                                            //Set the register bits as 00000000 to activate the gyro.
  HWire.endTransmission();                                      //End the transmission with the gyro.

  HWire.beginTransmission(gyro_address);                        //Start communication with the MPU-6050.
  HWire.write(0x1B);                                        //We want to write to the GYRO_CONFIG register (1B hex).
  HWire.write(0x08);                                            //Set the register bits as 00001000 (500dps full scale).
  HWire.endTransmission();                                      //End the transmission with the gyro.

  HWire.beginTransmission(gyro_address);                     //Start communication with the MPU-6050.
  HWire.write(0x1C);                                      //We want to write to the ACCEL_CONFIG register (1A hex).
  HWire.write(0x10);                                        //Set the register bits as 00010000 (+/- 8g full scale range).
  HWire.endTransmission();                                      //End the transmission with the gyro.

  HWire.beginTransmission(gyro_address);                        //Start communication with the MPU-6050.
  HWire.write(0x1A);                                            //We want to write to the CONFIG register (1A hex).
  HWire.write(0x03);                                //Set the register bits as 00000011 (Low Pass Filter to ~43Hz).
  HWire.endTransmission();   
  
  }

When the program holds at HWire.endTransmission i notice the PCB led flashes fast. Is this led used as some sort of error indication.

Arduino 2.1. STM32F103 Blue Pill. STLink. MAC computer.
Any comments welcome.

Why Wire (#included twice!?) and SoftWire together?

Is HWire.begin() okay in loop(), not setup()?

Have you run i2c_sniffer to find valid devices? On soft and hardware bus?

The Arduino LEDs are not, of themselves, used as error indicators. To know what is going wrong and why that (which?) LED flashes, you need to look at the library (which depends on which board you choose). Not enough information. Theoretically, all .end does is set SCL and SDA to LOW and that "shouldn't" cause an LED to flash unless the whole board is resetting or something.

That's for your comments.

DrDiettrich, the two includes was a cut and past error. HWire.begin(); and HWire.endTransmission(); do not cause a problem in the loop. As i said earlier i can read the device 'id' at the correct address.

JaBa, thanks, i will look into your suggestion.

Regards,

@horkesley, to solve a problem, you have to return to a situation that works and then you can go on from there.
That means you have to remove all the things that are wrong and even all the weird things and return to the most common way. You can not afford to make a big mess.

So please return to something normal.
Use only this include:

#include <Wire.h>

Remove the TwoWire, the HWire, the SoftWire and everything else that is not normal.

You could add the test for the ID in setup() and keep it there. So you know every time if that is working.

Can you show a photo, so we can see the MPU-6050 module and the wires ? If you power the MPU-6050 with 3.3V, then the voltage regulator on the module might not give enough voltage for your counterfeit MPU-6050. Do you use a flat ribbon cable with SDA next to SCL ? Did you connect the GNDs ?

My suggestion: Toss that MPU-6050 module away right now. I will wait while you do that.....
Is it gone? Good! Then buy a good sensor, your MPU-6050 was counterfeit.

If you show us a sketch, please show the full sketch.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.