180622 HJM : 10 Count sensing data RF send and bug fix
Fork of ADXL362 by
ADXL362.h@2:e484040b8f84, 2018-09-20 (annotated)
- Committer:
- jmhong
- Date:
- Thu Sep 20 06:34:12 2018 +0000
- Revision:
- 2:e484040b8f84
- Parent:
- 1:bf56b783747e
bug fix
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 | |
jmhong | 1:bf56b783747e | 25 | /* Class ADXL362: configure and connect to ADXL362 3-axis accelerometer. |
jmhong | 1:bf56b783747e | 26 | * Richard McWilliam |
rmcwilliam101 | 0:d9853774f233 | 27 | * |
jmhong | 1:bf56b783747e | 28 | * Example: |
rmcwilliam101 | 0:d9853774f233 | 29 | * |
jmhong | 1:bf56b783747e | 30 | * #include "mbed.h" |
jmhong | 1:bf56b783747e | 31 | * #include "ADXL362.h" |
rmcwilliam101 | 0:d9853774f233 | 32 | * |
jmhong | 1:bf56b783747e | 33 | * ADXL362 adxl362(p11, p12, p13, p10); // Accelerometer (mosi, miso, sclk, cs) |
rmcwilliam101 | 0:d9853774f233 | 34 | * |
jmhong | 1:bf56b783747e | 35 | * int main() |
jmhong | 1:bf56b783747e | 36 | * { |
jmhong | 1:bf56b783747e | 37 | * // local variables |
jmhong | 1:bf56b783747e | 38 | * int8_t x8 = 0; |
jmhong | 1:bf56b783747e | 39 | * int8_t y8 = 0; |
jmhong | 1:bf56b783747e | 40 | * int8_t z8 = 0; |
jmhong | 1:bf56b783747e | 41 | * uint8_t reg; |
rmcwilliam101 | 0:d9853774f233 | 42 | * |
jmhong | 1:bf56b783747e | 43 | * // set up SPI interface |
jmhong | 1:bf56b783747e | 44 | * adxl362.init_spi(); |
jmhong | 1:bf56b783747e | 45 | * // Set up accelerometer |
jmhong | 1:bf56b783747e | 46 | * adxl362.init_adxl362(); |
rmcwilliam101 | 0:d9853774f233 | 47 | * |
jmhong | 1:bf56b783747e | 48 | * // Check settings |
jmhong | 1:bf56b783747e | 49 | * reg = adxl362.ACC_ReadReg(FILTER_CTL); |
jmhong | 1:bf56b783747e | 50 | * printf("FILTER_CTL = 0x%X\r\n", reg); |
rmcwilliam101 | 0:d9853774f233 | 51 | * |
jmhong | 1:bf56b783747e | 52 | * adxl362.ACC_GetXYZ8(&x8, &y8, &z8); // Fetch sample from ADXL362 |
jmhong | 1:bf56b783747e | 53 | * wait(0.1); // Wait is required in this mode |
jmhong | 1:bf56b783747e | 54 | * |
jmhong | 1:bf56b783747e | 55 | * } |
rmcwilliam101 | 0:d9853774f233 | 56 | */ |
rmcwilliam101 | 0:d9853774f233 | 57 | class ADXL362 { |
jmhong | 1:bf56b783747e | 58 | |
jmhong | 1:bf56b783747e | 59 | public: |
jmhong | 1:bf56b783747e | 60 | // Set up object for communcation with ADXL362. Pins are mosi, miso, sclk, cs |
jmhong | 1:bf56b783747e | 61 | ADXL362(PinName mosi, PinName miso, PinName sclk, PinName cbs); |
jmhong | 1:bf56b783747e | 62 | //~ADXL362() {}; |
jmhong | 1:bf56b783747e | 63 | |
jmhong | 1:bf56b783747e | 64 | // Initialise the SPI interface for ADXL362 |
jmhong | 1:bf56b783747e | 65 | void init_spi(); |
jmhong | 1:bf56b783747e | 66 | |
jmhong | 1:bf56b783747e | 67 | // Initialise ADXL362 in basic capture mode, 8 bit pcakets. |
jmhong | 1:bf56b783747e | 68 | void init_adxl362(); |
jmhong | 1:bf56b783747e | 69 | |
jmhong | 1:bf56b783747e | 70 | // Fetch a single set of x,y,z packets indicating acceleration |
jmhong | 1:bf56b783747e | 71 | void ACC_GetXYZ8(int8_t* x8, int8_t* y8, int8_t* z8); |
rmcwilliam101 | 0:d9853774f233 | 72 | |
jmhong | 1:bf56b783747e | 73 | // Fetch a single set of x,y,z packets indicating acceleration |
jmhong | 1:bf56b783747e | 74 | void ACC_GetXYZ16(int16_t* x, int16_t* y, int16_t* z); |
jmhong | 1:bf56b783747e | 75 | |
jmhong | 1:bf56b783747e | 76 | // Read specified register of ADXL362 |
jmhong | 1:bf56b783747e | 77 | uint8_t ACC_ReadReg( uint8_t reg ); |
jmhong | 1:bf56b783747e | 78 | |
jmhong | 1:bf56b783747e | 79 | // Write to register of ADXL362 |
jmhong | 1:bf56b783747e | 80 | void ACC_WriteReg( uint8_t reg, uint8_t cmd ); |
jmhong | 1:bf56b783747e | 81 | |
jmhong | 1:bf56b783747e | 82 | private: |
jmhong | 1:bf56b783747e | 83 | SPI SPI_m; |
jmhong | 1:bf56b783747e | 84 | DigitalOut CBS_m; |
rmcwilliam101 | 0:d9853774f233 | 85 | }; |
rmcwilliam101 | 0:d9853774f233 | 86 | |
rmcwilliam101 | 0:d9853774f233 | 87 | #endif |