我试图从MPU9250中的AK8963中读取值Who I Am,如果我在其他骨骼中读取加速度计和陀螺仪的值,我没有问题,但当我尝试首先配置磁力计时,我需要知道i2c总线中是否有连接,但是,如果我运行i2c扫描,总是找到0x68-MPU9250地址,但从来没有找到AK8963 Addres 0X0C,我已经从Int_cpf配置了Bypass。。在这里用0x02注册地址0x37我的代码总是从AK8963的值Who I Am返回255。
这是我的代码
#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
}
''很可能您有一个没有mag.的变体…因为MPU9250已经退出几年来的生产,人们销售";MPU9250接线板";他们可以使用任何可用的变体kriswiner 说
检查下面的链接,这是一个病毒问题。
https://github.com/kriswiner/MPU9250/issues/486
我也遇到过同样的问题。唯一的解决方案是购买值得信赖的产品。