Driver for MPU9250 with SPI .
Dependents: MPU9250_SPI_Test MPU9250_SPI_Test ANCHOR_Navigation3 MPU9250_edit ... more
MPU9250 driver by SPI is working now.
Diff: MPU9250.cpp
- Revision:
- 8:492028cb604e
- Parent:
- 7:1bcd61cdbf18
- Child:
- 9:a8733542d0fb
diff -r 1bcd61cdbf18 -r 492028cb604e MPU9250.cpp --- a/MPU9250.cpp Sun Jun 29 07:17:22 2014 +0000 +++ b/MPU9250.cpp Mon Jun 30 13:15:53 2014 +0000 @@ -319,6 +319,43 @@ Magnetometer[i]=data/Magnetometer_divider; } } +void mpu9250_spi::read_all(){ + uint8_t response[21]; + int16_t bit_data; + float data; + int i; + + //Send I2C command at first + 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_HXL); //I2C slave 0 register address from where to begin data transfer + WriteReg(MPUREG_I2C_SLV0_CTRL, 0x87); //Read 7 bytes from the magnetometer + //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. + + //wait(0.001); + ReadRegs(MPUREG_ACCEL_XOUT_H,response,21); + //Get accelerometer value + for(i=0; i<3; i++) { + bit_data=((int16_t)response[i*2]<<8)|response[i*2+1]; + data=(float)bit_data; + accelerometer_data[i]=data/acc_divider; + } + //Get temperature + bit_data=((int16_t)response[i*2]<<8)|response[i*2+1]; + data=(float)bit_data; + Temperature=(data/340)+36.53; + //Get gyroscop value + for(i=4; i<7; i++) { + bit_data=((int16_t)response[i*2]<<8)|response[i*2+1]; + data=(float)bit_data; + gyroscope_data[i-4]=data/gyro_divider; + } + //Get Magnetometer value + for(i=7; i<10; i++) { + bit_data=((int16_t)response[i*2]<<8)|response[i*2+1]; + data=(float)bit_data; + Magnetometer[i-7]=data/Magnetometer_divider; + } +} /*----------------------------------------------------------------------------------------------- SPI SELECT AND DESELECT