![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
ADXL basic test
Dependencies: mbed
Fork of BLE_UARTConsole by
Revision 10:4e3a56a61c3b, committed 2015-01-30
- Comitter:
- smigielski
- Date:
- Fri Jan 30 07:31:38 2015 +0000
- Parent:
- 9:17b6ab281627
- Commit message:
- Read more registers
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 17b6ab281627 -r 4e3a56a61c3b main.cpp --- a/main.cpp Thu Jan 29 21:52:09 2015 +0000 +++ b/main.cpp Fri Jan 30 07:31:38 2015 +0000 @@ -1,21 +1,41 @@ #include "mbed.h" -SPI spi(P0_28, p0_24, P0_29); // mosi, miso, sclk +SPI spi(P0_28, P0_24, P0_29); // mosi, miso, sclk DigitalOut cs(P0_23); + +// ACC Registers #define ADXL362_DEVID_AD 0x00 +#define ADXL362_DEVID_MST 0x01 +#define ADXL362_PART_ID 0x02 +#define ADXL362_REV_ID 0x03 + +#define ADXL362_DATA 0x08 + #define ADXL362_READ_REGISTER 0x0b +void readRegister(uint8_t reg){ + cs = 0; + spi.write(ADXL362_READ_REGISTER); + spi.write(reg); + uint8_t val = spi.write(0x00); + cs = 1; +} + //Test that spi is working with adxl362 int main() { cs=1; while(1) { - cs = 0; - spi.write(ADXL362_READ_REGISTER); - spi.write(ADXL362_DEVID_AD); - //Device id is 0xAD - uint8_t val = spi.write(0x00); - cs = 1; - wait(1.0); + readRegister(ADXL362_DEVID_AD); + wait(0.5); + readRegister(ADXL362_DEVID_MST); + wait(0.5); + readRegister(ADXL362_PART_ID); + wait(0.5); + readRegister(ADXL362_REV_ID); + wait(0.5); + readRegister(ADXL362_DATA); + wait(0.5); } } +