Accelerometer test
Fork of BMA180 by
BMA180.h@0:ff755cb08068, 2012-08-01 (annotated)
- Committer:
- jsermita
- Date:
- Wed Aug 01 20:27:16 2012 +0000
- Revision:
- 0:ff755cb08068
First revision of a BMA180 accelerometer library to read X, Y, and Z acceleration.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jsermita | 0:ff755cb08068 | 1 | #include "mbed.h" |
jsermita | 0:ff755cb08068 | 2 | #ifndef MBED_BMA180_H |
jsermita | 0:ff755cb08068 | 3 | #define MBED_BMA180_H |
jsermita | 0:ff755cb08068 | 4 | |
jsermita | 0:ff755cb08068 | 5 | /******************DEFINED REGISTERS******************/ |
jsermita | 0:ff755cb08068 | 6 | #define CHIPID 0x00 |
jsermita | 0:ff755cb08068 | 7 | #define VERSION 0x01 |
jsermita | 0:ff755cb08068 | 8 | #define ACCXLSB 0x02 |
jsermita | 0:ff755cb08068 | 9 | #define ACCXMSB 0x03 |
jsermita | 0:ff755cb08068 | 10 | #define ACCYLSB 0x04 |
jsermita | 0:ff755cb08068 | 11 | #define ACCYMSB 0x05 |
jsermita | 0:ff755cb08068 | 12 | #define ACCZLSB 0x06 |
jsermita | 0:ff755cb08068 | 13 | #define ACCZMSB 0x07 |
jsermita | 0:ff755cb08068 | 14 | #define TEMP 0x08 |
jsermita | 0:ff755cb08068 | 15 | #define CTRL_REG0 0x0D |
jsermita | 0:ff755cb08068 | 16 | #define BWTCS 0x20 |
jsermita | 0:ff755cb08068 | 17 | #define DIS_I2C 0x27 // bit0 must be 1 for SPI |
jsermita | 0:ff755cb08068 | 18 | #define CTRL_REG3 0x21 // bit1 = new_data_int |
jsermita | 0:ff755cb08068 | 19 | #define RESET 0x10 // soft reset |
jsermita | 0:ff755cb08068 | 20 | #define RANGE 0x35 // 2g = 010 |
jsermita | 0:ff755cb08068 | 21 | |
jsermita | 0:ff755cb08068 | 22 | class BMA180 { |
jsermita | 0:ff755cb08068 | 23 | public: |
jsermita | 0:ff755cb08068 | 24 | BMA180(PinName _sdi, PinName _sdo, PinName _sck, PinName _cs, PinName _interrupt); |
jsermita | 0:ff755cb08068 | 25 | int validate(char idAddress, char verAddress); |
jsermita | 0:ff755cb08068 | 26 | void initBMA180(void); |
jsermita | 0:ff755cb08068 | 27 | void reset(void); |
jsermita | 0:ff755cb08068 | 28 | void readAxis(void); |
jsermita | 0:ff755cb08068 | 29 | void writeReg(uint8_t address, char data); |
jsermita | 0:ff755cb08068 | 30 | char readReg(uint8_t address); |
jsermita | 0:ff755cb08068 | 31 | void disInt(void); |
jsermita | 0:ff755cb08068 | 32 | |
jsermita | 0:ff755cb08068 | 33 | private: |
jsermita | 0:ff755cb08068 | 34 | SPI spi; |
jsermita | 0:ff755cb08068 | 35 | DigitalOut _csb; |
jsermita | 0:ff755cb08068 | 36 | DigitalOut _interrupt; |
jsermita | 0:ff755cb08068 | 37 | }; |
jsermita | 0:ff755cb08068 | 38 | |
jsermita | 0:ff755cb08068 | 39 | #endif |