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.