Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MPU9250_SPI mbed
Fork of MPU9250_AHRS by
Diff: main.cpp
- Revision:
- 6:ea0804dc7cae
- Parent:
- 5:abfc7660fde9
- Child:
- 7:758a94e02aa7
--- a/main.cpp Mon Jun 13 07:59:46 2016 +0000
+++ b/main.cpp Fri Jun 17 05:16:13 2016 +0000
@@ -1,98 +1,85 @@
/**
* Masahiro FURUKAWA - m.furukawa@ist.osaka-u.ac.jp
*
- * June 7, 2016
+ * June 17, 2016
*
- * LDXL362 Acceleration Sensor (Extended to Ch1 ~ Ch3)
+ * MPU9250 9DoF Sensor (Extended to Ch1 ~ Ch2)
*
**/
#include "mbed.h"
-#include "ADXL362.h"
-
-Serial pc(USBTX, USBRX);
+#include "MPU9250.h"
/*
- ~CS (Chip Select) p8
MOSI (Master Out Slave In) p5
MISO (Master In Slave Out p6
SCK (Serial Clock) p7
+ ~CS (Chip Select) p8
*/
+// https://developer.mbed.org/users/kylongmu/code/MPU9250_SPI_Test/file/5839d1b118bc/main.cpp
int main() {
+
+ Serial pc(USBTX, USBRX);
pc.baud(115200);
- ADXL362 *adxl362[6];
-
- adxl362[0] = new ADXL362( p8, p5, p6, p7);
- adxl362[1] = new ADXL362( p9, p5, p6, p7);
- adxl362[2] = new ADXL362( p10, p5, p6, p7);
- adxl362[3] = new ADXL362( p11, p5, p6, p7);
- adxl362[4] = new ADXL362( p12, p5, p6, p7);
- adxl362[5] = new ADXL362( p13, p5, p6, p7);
-
-
- // we need to wait at least 500ms after ADXL362 reset
- printf("\r\nInitializing . \r\n");
- for (int i=0; i<6; i++) {
- adxl362[i]->reset();
- wait_ms(600);
- }
-
-
- wait_ms(600);
+ SPI spi(p5, p6, p7);
+
+ //define the mpu9250 object
+ mpu9250_spi *imu[2];
- for (int i=0; i<6; i++)
- {
- adxl362[i]->frequency(20000);
- adxl362[i]->frequency(1000000);
- adxl362[i]->set_mode(ADXL362::MEASUREMENT);
- }
- //while(1) {
- for (int i=0; i<6; i++)
- {
- uint8_t err = false;
- uint8_t ad = static_cast<uint8_t>(adxl362[i]->read_reg(ADXL362::DEVID_AD));
- uint8_t mst = static_cast<uint8_t>(adxl362[i]->read_reg(ADXL362::DEVID_MST));
- uint8_t pid = static_cast<uint8_t>(adxl362[i]->read_reg(ADXL362::PARTID));
- uint8_t rid = static_cast<uint8_t>(adxl362[i]->read_reg(ADXL362::REVID));
- err |= (0xAD != ad);
- err |= (0x1D != mst);
- err |= (0xF2 != pid);
- err |= (0x02 != rid);
- if (err) printf("CH %d has error DevID_AD %02x DevID_MST %02x PartID %02x RevID %02x\r\n", i, ad, mst, pid, rid);
- }
- //}
-
+ imu[0] = new mpu9250_spi(spi, p8);
+ imu[1] = new mpu9250_spi(spi, p9);
+
+ int i=0;
+
+ if(imu[i]->init(1,BITS_DLPF_CFG_188HZ)){ //INIT the mpu9250
+ printf("\nCouldn't initialize MPU9250 via SPI!");
+ }
+ printf("\nWHOAMI=0x%2x\n",imu[i]->whoami()); //output the I2C address to know if SPI is working, it should be 104
+ wait(1);
+ printf("Gyro_scale=%u\n",imu[i]->set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros
+ wait(1);
+ printf("Acc_scale=%u\n",imu[i]->set_acc_scale(BITS_FS_16G)); //Set full scale range for accs
+ wait(1);
+ printf("AK8963 WHIAM=0x%2x\n",imu[i]->AK8963_whoami());
+ wait(0.1);
+ imu[i]->AK8963_calib_Magnetometer();
+
+ while(1) {
+ //myled = 1;
+ wait(0.1);
+ /*
+ imu[i]->read_temp();
+ imu[i]->read_acc();
+ imu[i]->read_rot();
+ imu[i]->AK8963_read_Magnetometer();
+ */
+ imu[i]->read_all();
+ printf("%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f\n",
+ imu[i]->Temperature,
+ imu[i]->gyroscope_data[0],
+ imu[i]->gyroscope_data[1],
+ imu[i]->gyroscope_data[2],
+ imu[i]->accelerometer_data[0],
+ imu[i]->accelerometer_data[1],
+ imu[i]->accelerometer_data[2],
+ imu[i]->Magnetometer[0],
+ imu[i]->Magnetometer[1],
+ imu[i]->Magnetometer[2]
+ );
+ //myled = 0;
+ //wait(0.5);
+ }
+
+ /*
uint64_t xyzt[6];
short xi[6],yi[6],zi[6];
while(1) {
-
-
- /* pc.putc('#');
- char ch;
- for(int i=8;i>2;i--)
- {
- ch = static_cast<uint8_t>(0xF&( t1>>(i*8) ) );
- pc.putc(ch);
- }
- pc.putc(',');
- for(int i=8;i>2;i--)
- {
- ch = static_cast<uint8_t>(0xF&( t2>>(i*8) ) );
- pc.putc(ch);
- }
- pc.putc(',');
- for(int i=8;i>2;i--)
- {
- ch = static_cast<uint8_t>(0xF&( t3>>(i*8) ) );
- pc.putc(ch);
- }
- */
for (int i=0; i<6; i++)
xyzt[i] = adxl362[i]->scan();
@@ -112,4 +99,5 @@
printf("\r\n");
wait_us(1);
}
+ */
}
