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: LSM9DS1_ADVRO mbed
main.cpp@1:182761476d79, 2017-06-21 (annotated)
- Committer:
- ChangYuHsuan
- Date:
- Wed Jun 21 09:07:13 2017 +0000
- Revision:
- 1:182761476d79
- Parent:
- 0:a78e30188b92
LSM9DS1 SPI ver 1.01;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ChangYuHsuan | 0:a78e30188b92 | 1 | #include "LSM9DS1.h" |
| ChangYuHsuan | 0:a78e30188b92 | 2 | |
| ChangYuHsuan | 0:a78e30188b92 | 3 | void timerInterrupt(); |
| ChangYuHsuan | 0:a78e30188b92 | 4 | |
| ChangYuHsuan | 0:a78e30188b92 | 5 | DigitalOut myled(LED1); |
| ChangYuHsuan | 0:a78e30188b92 | 6 | Serial pc(USBTX, USBRX); |
| ChangYuHsuan | 0:a78e30188b92 | 7 | |
| ChangYuHsuan | 0:a78e30188b92 | 8 | Ticker timer1; |
| ChangYuHsuan | 0:a78e30188b92 | 9 | #define PERIOD 10000 // unit: us |
| ChangYuHsuan | 0:a78e30188b92 | 10 | |
| ChangYuHsuan | 0:a78e30188b92 | 11 | // IMU in SPI mode |
| ChangYuHsuan | 0:a78e30188b92 | 12 | SPI imuSpi(PC_12, PC_11, PC_10); // MOSI, MISO, SCLK |
| ChangYuHsuan | 0:a78e30188b92 | 13 | DigitalOut agCS(PA_13); |
| ChangYuHsuan | 0:a78e30188b92 | 14 | DigitalOut mCS(PA_14); |
| ChangYuHsuan | 0:a78e30188b92 | 15 | LSM9DS1 imu(&imuSpi, &agCS, &mCS, 0xD6, 0x3C); |
| ChangYuHsuan | 0:a78e30188b92 | 16 | |
| ChangYuHsuan | 1:182761476d79 | 17 | float degree = 0.0f; |
| ChangYuHsuan | 0:a78e30188b92 | 18 | |
| ChangYuHsuan | 0:a78e30188b92 | 19 | int main() { |
| ChangYuHsuan | 0:a78e30188b92 | 20 | |
| ChangYuHsuan | 0:a78e30188b92 | 21 | pc.baud(115200); |
| ChangYuHsuan | 0:a78e30188b92 | 22 | |
| ChangYuHsuan | 1:182761476d79 | 23 | pc.printf("Start LSM9DS1\n\r"); |
| ChangYuHsuan | 1:182761476d79 | 24 | |
| ChangYuHsuan | 0:a78e30188b92 | 25 | bool status = imu.begin(); |
| ChangYuHsuan | 0:a78e30188b92 | 26 | pc.printf("connect or not: %d\n\r", status); |
| ChangYuHsuan | 1:182761476d79 | 27 | |
| ChangYuHsuan | 0:a78e30188b92 | 28 | imu.calibrate(); |
| ChangYuHsuan | 1:182761476d79 | 29 | wait(1); |
| ChangYuHsuan | 0:a78e30188b92 | 30 | |
| ChangYuHsuan | 0:a78e30188b92 | 31 | timer1.attach_us(&timerInterrupt, PERIOD); |
| ChangYuHsuan | 0:a78e30188b92 | 32 | |
| ChangYuHsuan | 0:a78e30188b92 | 33 | while(1) { |
| ChangYuHsuan | 0:a78e30188b92 | 34 | |
| ChangYuHsuan | 1:182761476d79 | 35 | pc.printf("gz: %.3f gzBias: %.3f degree: %.3f \n\r", imu.gz, imu.gBias[2], degree); |
| ChangYuHsuan | 0:a78e30188b92 | 36 | |
| ChangYuHsuan | 0:a78e30188b92 | 37 | wait(0.01); |
| ChangYuHsuan | 0:a78e30188b92 | 38 | } |
| ChangYuHsuan | 0:a78e30188b92 | 39 | } |
| ChangYuHsuan | 0:a78e30188b92 | 40 | |
| ChangYuHsuan | 0:a78e30188b92 | 41 | void timerInterrupt() |
| ChangYuHsuan | 0:a78e30188b92 | 42 | { |
| ChangYuHsuan | 0:a78e30188b92 | 43 | imu.readGyro(); |
| ChangYuHsuan | 0:a78e30188b92 | 44 | |
| ChangYuHsuan | 1:182761476d79 | 45 | degree += imu.gz * PERIOD / 1000000.0f; |
| ChangYuHsuan | 1:182761476d79 | 46 | } |