ICM20602_I2C(invensense)---stm32f767zi
Fork of NTOUEE-mbed-I2C_MPU6500 by
main.cpp@0:95e46ae24046, 2016-10-21 (annotated)
- Committer:
- rkuo2000
- Date:
- Fri Oct 21 02:52:40 2016 +0000
- Revision:
- 0:95e46ae24046
mbed I2C reading MPU6500
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rkuo2000 | 0:95e46ae24046 | 1 | /// using NuMaker-PFM-NUC472 I2C0 to read 3-axis accelerometer & 3-axis gyroscope (MPU6500) |
rkuo2000 | 0:95e46ae24046 | 2 | #include "mbed.h" |
rkuo2000 | 0:95e46ae24046 | 3 | #include "mpu6500.h" |
rkuo2000 | 0:95e46ae24046 | 4 | |
rkuo2000 | 0:95e46ae24046 | 5 | I2C i2c0(PC_9, PA_15); // I2C0_SDA, I2C0_SCL |
rkuo2000 | 0:95e46ae24046 | 6 | |
rkuo2000 | 0:95e46ae24046 | 7 | MPU6500 IMU; // on-board IMU is MPU6500 |
rkuo2000 | 0:95e46ae24046 | 8 | |
rkuo2000 | 0:95e46ae24046 | 9 | int main() { |
rkuo2000 | 0:95e46ae24046 | 10 | int16_t accX, accY, accZ; |
rkuo2000 | 0:95e46ae24046 | 11 | int16_t gyroX, gyroY, gyroZ; |
rkuo2000 | 0:95e46ae24046 | 12 | |
rkuo2000 | 0:95e46ae24046 | 13 | i2c0.frequency(400000); |
rkuo2000 | 0:95e46ae24046 | 14 | IMU.initialize(); |
rkuo2000 | 0:95e46ae24046 | 15 | |
rkuo2000 | 0:95e46ae24046 | 16 | while(true) { |
rkuo2000 | 0:95e46ae24046 | 17 | accX = IMU.getAccelXvalue(); |
rkuo2000 | 0:95e46ae24046 | 18 | accY = IMU.getAccelYvalue(); |
rkuo2000 | 0:95e46ae24046 | 19 | accZ = IMU.getAccelZvalue(); |
rkuo2000 | 0:95e46ae24046 | 20 | gyroX= IMU.getGyroXvalue(); |
rkuo2000 | 0:95e46ae24046 | 21 | gyroY= IMU.getGyroYvalue(); |
rkuo2000 | 0:95e46ae24046 | 22 | gyroZ= IMU.getGyroZvalue(); |
rkuo2000 | 0:95e46ae24046 | 23 | printf("Acc: %6d, %6d, %6d, ", accX, accY, accZ); |
rkuo2000 | 0:95e46ae24046 | 24 | printf("Gyro:%6d, %6d, %6d\n\r", gyroX, gyroY, gyroZ); |
rkuo2000 | 0:95e46ae24046 | 25 | } |
rkuo2000 | 0:95e46ae24046 | 26 | } |