180622 HJM : 10 Count sensing data RF send 180718 HJM : 8 Count sensing data RF send, certTest, Temperature(cold) test
Fork of ADXL362 by
ADXL362.h@0:d9853774f233, 2016-03-03 (annotated)
- Committer:
- rmcwilliam101
- Date:
- Thu Mar 03 13:49:03 2016 +0000
- Revision:
- 0:d9853774f233
- Child:
- 1:bf56b783747e
AXDL library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rmcwilliam101 | 0:d9853774f233 | 1 | #ifndef _ADXL362_H_ |
rmcwilliam101 | 0:d9853774f233 | 2 | #define _ADXL362_H_ |
rmcwilliam101 | 0:d9853774f233 | 3 | |
rmcwilliam101 | 0:d9853774f233 | 4 | #include "mbed.h" |
rmcwilliam101 | 0:d9853774f233 | 5 | |
rmcwilliam101 | 0:d9853774f233 | 6 | // ACC Registers |
rmcwilliam101 | 0:d9853774f233 | 7 | #define ID0 0x00 |
rmcwilliam101 | 0:d9853774f233 | 8 | #define STATUS 0x0b |
rmcwilliam101 | 0:d9853774f233 | 9 | #define FIFO_EL 0x0c |
rmcwilliam101 | 0:d9853774f233 | 10 | #define FIFO_EH 0x0d |
rmcwilliam101 | 0:d9853774f233 | 11 | #define RESET 0x1f |
rmcwilliam101 | 0:d9853774f233 | 12 | #define FIFO_CTL 0x28 |
rmcwilliam101 | 0:d9853774f233 | 13 | #define FIFO_SAM 0x29 |
rmcwilliam101 | 0:d9853774f233 | 14 | #define INTMAP1 0x2a |
rmcwilliam101 | 0:d9853774f233 | 15 | #define INTMAP2 0x2b |
rmcwilliam101 | 0:d9853774f233 | 16 | #define FILTER_CTL 0x2c |
rmcwilliam101 | 0:d9853774f233 | 17 | #define POWER_CTL 0x2d |
rmcwilliam101 | 0:d9853774f233 | 18 | #define WR_SPI 0x0a |
rmcwilliam101 | 0:d9853774f233 | 19 | #define RD_SPI 0x0b |
rmcwilliam101 | 0:d9853774f233 | 20 | #define RD_FIFO 0x0d |
rmcwilliam101 | 0:d9853774f233 | 21 | #define DOWN 0 |
rmcwilliam101 | 0:d9853774f233 | 22 | #define UP 1 |
rmcwilliam101 | 0:d9853774f233 | 23 | #define SAMPLE_SET 128 |
rmcwilliam101 | 0:d9853774f233 | 24 | |
rmcwilliam101 | 0:d9853774f233 | 25 | /* Class ADXL362: configure and connect to ADXL362 3-axis accelerometer. |
rmcwilliam101 | 0:d9853774f233 | 26 | * Richard McWilliam |
rmcwilliam101 | 0:d9853774f233 | 27 | * |
rmcwilliam101 | 0:d9853774f233 | 28 | * Example: |
rmcwilliam101 | 0:d9853774f233 | 29 | * |
rmcwilliam101 | 0:d9853774f233 | 30 | * #include "mbed.h" |
rmcwilliam101 | 0:d9853774f233 | 31 | * #include "ADXL362.h" |
rmcwilliam101 | 0:d9853774f233 | 32 | * |
rmcwilliam101 | 0:d9853774f233 | 33 | * ADXL362 adxl362(p11, p12, p13, p10); // Accelerometer (mosi, miso, sclk, cs) |
rmcwilliam101 | 0:d9853774f233 | 34 | * |
rmcwilliam101 | 0:d9853774f233 | 35 | * int main() |
rmcwilliam101 | 0:d9853774f233 | 36 | * { |
rmcwilliam101 | 0:d9853774f233 | 37 | * // local variables |
rmcwilliam101 | 0:d9853774f233 | 38 | * int8_t x8 = 0; |
rmcwilliam101 | 0:d9853774f233 | 39 | * int8_t y8 = 0; |
rmcwilliam101 | 0:d9853774f233 | 40 | * int8_t z8 = 0; |
rmcwilliam101 | 0:d9853774f233 | 41 | * uint8_t reg; |
rmcwilliam101 | 0:d9853774f233 | 42 | * |
rmcwilliam101 | 0:d9853774f233 | 43 | * // set up SPI interface |
rmcwilliam101 | 0:d9853774f233 | 44 | * adxl362.init_spi(); |
rmcwilliam101 | 0:d9853774f233 | 45 | * // Set up accelerometer |
rmcwilliam101 | 0:d9853774f233 | 46 | * adxl362.init_adxl362(); |
rmcwilliam101 | 0:d9853774f233 | 47 | * |
rmcwilliam101 | 0:d9853774f233 | 48 | * // Check settings |
rmcwilliam101 | 0:d9853774f233 | 49 | * reg = adxl362.ACC_ReadReg(FILTER_CTL); |
rmcwilliam101 | 0:d9853774f233 | 50 | * printf("FILTER_CTL = 0x%X\r\n", reg); |
rmcwilliam101 | 0:d9853774f233 | 51 | * |
rmcwilliam101 | 0:d9853774f233 | 52 | * adxl362.ACC_GetXYZ8(&x8, &y8, &z8); // Fetch sample from ADXL362 |
rmcwilliam101 | 0:d9853774f233 | 53 | * wait(0.1); // Wait is required in this mode |
rmcwilliam101 | 0:d9853774f233 | 54 | * |
rmcwilliam101 | 0:d9853774f233 | 55 | * } |
rmcwilliam101 | 0:d9853774f233 | 56 | */ |
rmcwilliam101 | 0:d9853774f233 | 57 | class ADXL362 { |
rmcwilliam101 | 0:d9853774f233 | 58 | |
rmcwilliam101 | 0:d9853774f233 | 59 | public: |
rmcwilliam101 | 0:d9853774f233 | 60 | // Set up object for communcation with ADXL362. Pins are mosi, miso, sclk, cs |
rmcwilliam101 | 0:d9853774f233 | 61 | ADXL362(PinName mosi, PinName miso, PinName sclk, PinName cbs); |
rmcwilliam101 | 0:d9853774f233 | 62 | //~ADXL362() {}; |
rmcwilliam101 | 0:d9853774f233 | 63 | |
rmcwilliam101 | 0:d9853774f233 | 64 | // Initialise the SPI interface for ADXL362 |
rmcwilliam101 | 0:d9853774f233 | 65 | void init_spi(); |
rmcwilliam101 | 0:d9853774f233 | 66 | |
rmcwilliam101 | 0:d9853774f233 | 67 | // Initialise ADXL362 in basic capture mode, 8 bit pcakets. |
rmcwilliam101 | 0:d9853774f233 | 68 | void init_adxl362(); |
rmcwilliam101 | 0:d9853774f233 | 69 | |
rmcwilliam101 | 0:d9853774f233 | 70 | // Fetch a single set of x,y,z packets indicating acceleration |
rmcwilliam101 | 0:d9853774f233 | 71 | void ACC_GetXYZ8(int8_t* x, int8_t* y, int8_t* z); |
rmcwilliam101 | 0:d9853774f233 | 72 | |
rmcwilliam101 | 0:d9853774f233 | 73 | // Read specified register of ADXL362 |
rmcwilliam101 | 0:d9853774f233 | 74 | uint8_t ACC_ReadReg( uint8_t reg ); |
rmcwilliam101 | 0:d9853774f233 | 75 | |
rmcwilliam101 | 0:d9853774f233 | 76 | // Write to register of ADXL362 |
rmcwilliam101 | 0:d9853774f233 | 77 | void ACC_WriteReg( uint8_t reg, uint8_t cmd ); |
rmcwilliam101 | 0:d9853774f233 | 78 | |
rmcwilliam101 | 0:d9853774f233 | 79 | private: |
rmcwilliam101 | 0:d9853774f233 | 80 | SPI SPI_m; |
rmcwilliam101 | 0:d9853774f233 | 81 | DigitalOut CBS_m; |
rmcwilliam101 | 0:d9853774f233 | 82 | |
rmcwilliam101 | 0:d9853774f233 | 83 | }; |
rmcwilliam101 | 0:d9853774f233 | 84 | |
rmcwilliam101 | 0:d9853774f233 | 85 | #endif |