MPU9250 SPI Driver
Diff: MPU9250.cpp
- Revision:
- 6:c82c48348f8c
- Parent:
- 5:f15d1d9d1561
- Child:
- 7:1bcd61cdbf18
diff -r f15d1d9d1561 -r c82c48348f8c MPU9250.cpp --- a/MPU9250.cpp Sun Jun 29 06:38:21 2014 +0000 +++ b/MPU9250.cpp Sun Jun 29 07:06:12 2014 +0000 @@ -73,7 +73,7 @@ {0x81, MPUREG_I2C_SLV0_CTRL}, //Enable I2C and set 1 byte {AK8963_CNTL1, MPUREG_I2C_SLV0_REG}, //I2C slave 0 register address from where to begin data transfer - {0x02, MPUREG_I2C_SLV0_DO}, // Register value to continuous measurement in 14bit + {0x12, MPUREG_I2C_SLV0_DO}, // Register value to continuous measurement in 16bit {0x81, MPUREG_I2C_SLV0_CTRL} //Enable I2C and set 1 byte @@ -286,18 +286,19 @@ set_acc_scale(temp_scale); } -unsigned int mpu9250_spi::AK8963_whoami(){ - unsigned int response; +uint8_t mpu9250_spi::AK8963_whoami(){ + uint8_t response[2]; WriteReg(MPUREG_I2C_SLV0_ADDR,AK8963_I2C_ADDR|READ_FLAG); //Set the I2C slave addres of AK8963 and set for read. WriteReg(MPUREG_I2C_SLV0_REG, AK8963_WIA); //I2C slave 0 register address from where to begin data transfer - WriteReg(MPUREG_I2C_SLV0_CTRL, 0x81); //Read 1 byte from the magnetometer + WriteReg(MPUREG_I2C_SLV0_CTRL, 0x82); //Read 1 byte from the magnetometer //WriteReg(MPUREG_I2C_SLV0_CTRL, 0x81); //Enable I2C and set bytes - wait(0.1); - response=WriteReg(MPUREG_EXT_SENS_DATA_00, 0x00); //Read I2C + wait(0.001); + //response[0]=WriteReg(MPUREG_EXT_SENS_DATA_01|READ_FLAG, 0x00); //Read I2C + ReadRegs(MPUREG_EXT_SENS_DATA_00,response,2); //response=WriteReg(MPUREG_I2C_SLV0_DO, 0x00); //Read I2C - return response; + return response[0]; } void mpu9250_spi::AK8963_read_Magnetometer(){ uint8_t response[7]; @@ -309,7 +310,7 @@ WriteReg(MPUREG_I2C_SLV0_REG, AK8963_HXL); //I2C slave 0 register address from where to begin data transfer WriteReg(MPUREG_I2C_SLV0_CTRL, 0x87); //Read 6 bytes from the magnetometer - wait(0.01); + wait(0.001); ReadRegs(MPUREG_EXT_SENS_DATA_00,response,7); //must start your read from AK8963A register 0x03 and read seven bytes so that upon read of ST2 register 0x09 the AK8963A will unlatch the data registers for the next measurement. for(i=0; i<3; i++) {