输出:-我得到的是读取每个寄存器(对应于磁力计)的0xFF。另一方面,我能够访问寄存器的加速度计和陀螺仪完美。我已经初始化系统,禁用i2c主模式,启用i2c旁路模式。下面是我用来初始化系统的代码:-
single_byte_write(0x6B,0x01);
single_byte_write(0x19,0x01);
single_byte_write(0x1A,0x02);
single_byte_write(0x1B,0x11);
single_byte_write(0x1C,0x10);
single_byte_write(0x6A,0x00);
single_byte_write(0x37,0x02);
(' single_byte_write(address,data)将数据字节写入带有' address '的寄存器到从地址0x69 ')
我访问了accel寄存器。和陀螺。如下:-single_byte_read (0 x75 wia_mpu);它返回0x68,这是正确的作为who_i_am寄存器。但当我试图访问磁强计寄存器为:-single_byte_read_compass (0 x00 wia_compass);它返回0xFF,而它应该返回0x48。
为了确保single_byte_read_compass()/single_byte_write_compass()正常工作,我使用这些函数改变了从地址(从' 0x0C '到' 0x69 ')来访问accel的寄存器。和陀螺。
(' single_byte_read() '和' single_byte_read_compass() '之间的区别只是前者使用从地址为' 0x69 ',而后者使用' 0x0C '作为从地址。我也尝试过' 0x0D ', ' 0x0E '和' 0x0F '作为从地址,但输出保持不变。
我也确认了MPU9150是否为直通模式。我已经在示波器的帮助下检查了引脚"ES_DA"的输出,即pin6和SDA,即pin24,结果完全相同,启用了旁路模式。当禁用主模式和旁路模式时,' ES_DA '的输出始终为零。
我也尝试了与上面相同的过程,不仅仅是一个,而是许多mpu9150,但输出保持不变,因此很可能存在一些问题与代码。
这是我用来初始化MPU9150的代码,它适用于我(这是我在互联网上找到的修改后的arduino版本):
void MPU9150::initialize(){
write(MPU9150_PWR_MGMT_1, 0); //Wake up
initializeCompass();
}
void MPU9150::initializeCompass(){
this->i2cDevice.address = this->i2cDevice.compass; // 0x0C or 0x0D
write(0x0A, 0x00); //PowerDownMode
write(0x0A, 0x0F); //SelfTest
write(0x0A, 0x00); //PowerDownMode
this->i2cDevice.address = this->i2cDevice.mpu; //0x68 or 0x69
write(0x24, 0x40); //Wait for Data at Slave0
write(0x25, 0x8C); //Set i2c address at slave0 at 0x0C
write(0x26, 0x02); //Set where reading at slave 0 starts
write(0x27, 0x88); //set offset at start reading and enable
write(0x28, 0x0C); //set i2c address at slv1 at 0x0C
write(0x29, 0x0A); //Set where reading at slave 1 starts
write(0x2A, 0x81); //Enable at set length to 1
write(0x64, 0x01); //overvride register
write(0x67, 0x03); //set delay rate
write(0x01, 0x80);
write(0x34, 0x04); //set i2c slv4 delay
write(0x64, 0x00); //override register
write(0x6A, 0x00); //clear usr setting
write(0x64, 0x01); //override register
write(0x6A, 0x20); //enable master i2c mode
write(0x34, 0x13); //disable slv4
}
然后读取磁力计:
void MPU9150::readCompass()
{
data.compass.x = read(MPU9150_CMPS_XOUT_L,MPU9150_CMPS_XOUT_H);
data.compass.y = read(MPU9150_CMPS_YOUT_L,MPU9150_CMPS_YOUT_H);
data.compass.z = read(MPU9150_CMPS_ZOUT_L,MPU9150_CMPS_ZOUT_H);
}
地点:
//MPU9150 Compass
#define MPU9150_CMPS_XOUT_L 0x4A // R
#define MPU9150_CMPS_XOUT_H 0x4B // R
#define MPU9150_CMPS_YOUT_L 0x4C // R
#define MPU9150_CMPS_YOUT_H 0x4D // R
#define MPU9150_CMPS_ZOUT_L 0x4E // R
#define MPU9150_CMPS_ZOUT_H 0x4F // R