Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ADXL362 by
ADXL362.h
00001 #ifndef _ADXL362_H_ 00002 #define _ADXL362_H_ 00003 00004 #include "mbed.h" 00005 00006 // ACC Registers 00007 #define ID0 0x00 00008 #define STATUS 0x0b 00009 #define FIFO_EL 0x0c 00010 #define FIFO_EH 0x0d 00011 #define RESET 0x1f 00012 #define FIFO_CTL 0x28 00013 #define FIFO_SAM 0x29 00014 #define INTMAP1 0x2a 00015 #define INTMAP2 0x2b 00016 #define FILTER_CTL 0x2c 00017 #define POWER_CTL 0x2d 00018 #define WR_SPI 0x0a 00019 #define RD_SPI 0x0b 00020 #define RD_FIFO 0x0d 00021 #define DOWN 0 00022 #define UP 1 00023 #define SAMPLE_SET 128 00024 00025 /* Class ADXL362: configure and connect to ADXL362 3-axis accelerometer. 00026 * Richard McWilliam 00027 * 00028 * Example: 00029 * 00030 * #include "mbed.h" 00031 * #include "ADXL362.h" 00032 * 00033 * ADXL362 adxl362(p11, p12, p13, p10); // Accelerometer (mosi, miso, sclk, cs) 00034 * 00035 * int main() 00036 * { 00037 * // local variables 00038 * int8_t x8 = 0; 00039 * int8_t y8 = 0; 00040 * int8_t z8 = 0; 00041 * uint8_t reg; 00042 * 00043 * // set up SPI interface 00044 * adxl362.init_spi(); 00045 * // Set up accelerometer 00046 * adxl362.init_adxl362(); 00047 * 00048 * // Check settings 00049 * reg = adxl362.ACC_ReadReg(FILTER_CTL); 00050 * printf("FILTER_CTL = 0x%X\r\n", reg); 00051 * 00052 * adxl362.ACC_GetXYZ8(&x8, &y8, &z8); // Fetch sample from ADXL362 00053 * wait(0.1); // Wait is required in this mode 00054 * 00055 * } 00056 */ 00057 class ADXL362 { 00058 00059 public: 00060 // Set up object for communcation with ADXL362. Pins are mosi, miso, sclk, cs 00061 ADXL362(PinName mosi, PinName miso, PinName sclk, PinName cbs); 00062 //~ADXL362() {}; 00063 00064 // Initialise the SPI interface for ADXL362 00065 void init_spi(); 00066 00067 // Initialise ADXL362 in basic capture mode, 8 bit pcakets. 00068 void init_adxl362(); 00069 00070 // Fetch a single set of x,y,z packets indicating acceleration 00071 void ACC_GetXYZ8(int8_t* x8, int8_t* y8, int8_t* z8); 00072 00073 // Fetch a single set of x,y,z packets indicating acceleration 00074 void ACC_GetXYZ16(int16_t* x, int16_t* y, int16_t* z); 00075 00076 // Read specified register of ADXL362 00077 uint8_t ACC_ReadReg( uint8_t reg ); 00078 00079 // Write to register of ADXL362 00080 void ACC_WriteReg( uint8_t reg, uint8_t cmd ); 00081 00082 private: 00083 SPI SPI_m; 00084 DigitalOut CBS_m; 00085 }; 00086 00087 #endif
Generated on Thu Aug 18 2022 22:18:55 by
1.7.2
