![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Simple test for MPU connectivity
Dependencies: mbed
main.cpp@0:7c2bb0b8ea73, 2015-01-29 (annotated)
- Committer:
- smigielski
- Date:
- Thu Jan 29 21:44:33 2015 +0000
- Revision:
- 0:7c2bb0b8ea73
initial version of mputest
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
smigielski | 0:7c2bb0b8ea73 | 1 | #include "mbed.h" |
smigielski | 0:7c2bb0b8ea73 | 2 | |
smigielski | 0:7c2bb0b8ea73 | 3 | SPI spi(P0_28, P0_24, P0_29); // mosi, miso, sclk |
smigielski | 0:7c2bb0b8ea73 | 4 | DigitalOut cs(P0_18); |
smigielski | 0:7c2bb0b8ea73 | 5 | |
smigielski | 0:7c2bb0b8ea73 | 6 | #define MPU9250_WHOAMI 0x75 |
smigielski | 0:7c2bb0b8ea73 | 7 | #define MPU9250_READ_FLAG 0x80 |
smigielski | 0:7c2bb0b8ea73 | 8 | |
smigielski | 0:7c2bb0b8ea73 | 9 | //Test that spi is working with mpu9250 |
smigielski | 0:7c2bb0b8ea73 | 10 | int main() { |
smigielski | 0:7c2bb0b8ea73 | 11 | cs=1; |
smigielski | 0:7c2bb0b8ea73 | 12 | while(1) { |
smigielski | 0:7c2bb0b8ea73 | 13 | cs = 0; |
smigielski | 0:7c2bb0b8ea73 | 14 | spi.write(MPU9250_WHOAMI| MPU9250_READ_FLAG); |
smigielski | 0:7c2bb0b8ea73 | 15 | uint8_t val = spi.write(0x00); |
smigielski | 0:7c2bb0b8ea73 | 16 | //Device id is 0x71 |
smigielski | 0:7c2bb0b8ea73 | 17 | cs = 1; |
smigielski | 0:7c2bb0b8ea73 | 18 | wait(1.0); |
smigielski | 0:7c2bb0b8ea73 | 19 | } |
smigielski | 0:7c2bb0b8ea73 | 20 | } |