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