arduinoaccelerometeresp8266magnetometerelectronic-signature

How can I get Ak8963 Address from MPU9250


I try to read the value Who I Am from AK8963 in MPU9250, if I read the values of the accelerometer and the gyroscope in other skecth I have not problems, but When I try to configure the magnetometer first I need to know if there is connection in i2c bus but, If I run i2c Scan always find 0x68-- MPU9250 address but never AK8963 Addres 0X0C, I have already configured Bypass from Int_cpf.. register Address 0x37 with 0x02 here my code always return 255 from value Who I Am from AK8963.

Here my code

 #include <Wire.h>
     const uint8_t AK8963 = 0X0C;//
    const uint8_t WIA = 0X00;
    const uint8_t MPU9250 = 0x68;

     const uint8_t ACCEL_XOUT_H = 0X3B;//direccion del registro donde se aloja el valor de lectura 
      acelerometro

    const uint8_t SMPLRT_DIV = 0X19;//registro divisor de frecuencia 
    //la frecuencia de muestreo del sensor es igual a la frecuencia del giroscopio divido 
    //el valor  dado en el registro SMPLRT_DIV + 1
    //Frecuencia de muestreo  giroscopio output rate/(1+SMPLRT_DIV) = 8KHZ/8 = 1KHZ



const uint8_t CONFIG = 0x1A;//Registro de configuracion de tasas de muestro y filtro acelerometro y giroscopio
const uint8_t USER_CTRL   =  0x6A;
const uint8_t SIGNAL_PATH_RESET = 0X68;
const uint8_t FIFO_EN = 0X23;
const uint8_t INT_ENABLE = 0X38;
const uint8_t PWR_MGMT_1   =  0x6B;
const uint8_t PWR_MGMT_2   =  0x6C;
const uint8_t ACCEL_CONFIG = 0X1C;//registro configuracion acelerometro
const uint8_t INT_PIN_CFG = 0X37;


void MPU9260_CONFIG()
{

delay(150);//espero 100 milisegundos
I2CWRITER(MPU9250 , SMPLRT_DIV, 0X07);//Envio el numero 7 al registro 
I2CWRITER(MPU9250 , CONFIG, 0X00);//Giroscopio con frecuencia de muestreo de 8KHZ
I2CWRITER(MPU9250 , FIFO_EN, 0X00);
I2CWRITER(MPU9250 , ACCEL_CONFIG , 0x00);
I2CWRITER(MPU9250 , INT_ENABLE, 0X01);
I2CWRITER(MPU9250 , SIGNAL_PATH_RESET, 0x00);
I2CWRITER(MPU9250 , USER_CTRL , 0X00);
I2CWRITER(MPU9250 , PWR_MGMT_1, 0x01);
I2CWRITER(MPU9250 , PWR_MGMT_2, 0x00);
I2CWRITER(MPU9250 , INT_PIN_CFG, 0x02);

}
void I2CWRITER(uint8_t deviceAddress, uint8_t regAdress, uint8_t dato)
{
   Wire.beginTransmission(deviceAddress);  
   Wire.write(regAdress);
   Wire.write(dato);
   Wire.endTransmission();


}



void setup()

{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
  MPU9250_CONFIG();
  
  
}

void loop() {

  Wire.beginTransmission(AK8963);
  Wire.write(WIA);  
  Wire.requestFrom(AK8963, 1);    
  byte c = Wire.read(); // receive a byte as character
  Serial.println(c);  
  delay(500);// print the character
  }

Solution

  • ''' Likely you have a variant without the mag...since MPU9250 has been out of production for a couple of years now it is not surprising people are selling "MPU9250 Breakout Boards" with any available variants they can find ''' said kriswiner

    Check the link bellow it is a viral problem.

    https://github.com/kriswiner/MPU9250/issues/486

    I have faced the same problem. and the only solution is buying a trustworthy product.