base program for tilt measurement
Dependencies: COG4050_ADT7420 ADXL362
Fork of COG4050_adxl355_adxl357-ver2 by
Revision 2:14dc1ec57f3b, committed 2018-08-07
- Comitter:
- vtoffoli
- Date:
- Tue Aug 07 12:49:37 2018 +0000
- Parent:
- 1:d3aeaa02781d
- Child:
- 3:ee052fdb4331
- Commit message:
- draft
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ADXL35x/ADXL355.cpp Tue Aug 07 12:49:37 2018 +0000
@@ -0,0 +1,51 @@
+#include <stdint.h>
+#include "mbed.h"
+#include "ADXL355.h"
+
+
+//DigitalOut(cs); ///< DigitalOut instance for the chipselect of the ADXL
+//DigitalOut int1; ///< DigitalOut instance for the chipselect of the ADXL
+//DigitalOut int2; ///< DigitalOut instance for the chipselect of the ADXL
+
+ADXL355::ADXL355(PinName cs_pin, PinName MOSI, PinName MISO, PinName SCK): adxl355(MOSI, MISO, SCK), cs(cs_pin){
+ cs = 1;
+ adxl355.format(8,_SPI_MODE);
+ adxl355.lock();
+}
+
+/** SPI bus frequency */
+void ADXL355::frequency(int hz){
+ adxl355.frequency(hz);
+}
+
+/** Software resets */
+ void ADXL355::reset(void){
+ adxl355.format(8, _SPI_MODE);
+ cs = false;
+ // Writing Code 0x52 (representing the letter, R, in ASCII or unicode) to this register immediately resets the ADXL362.
+ write_reg(RESET, _RESET);
+ cs = true;
+}
+
+ /** Writes the reg register with data */
+void ADXL355::write_reg(ADXL355_register_t reg, uint8_t data){
+ adxl355.format(8, _SPI_MODE);
+ cs = false;
+ adxl355.write(reg<<1 | _WRITE_REG_CMD);
+ adxl355.write(data);
+ cs = true;
+}
+void ADXL355::write_reg_u16(ADXL355_register_t reg, uint16_t data){}
+
+/** Reads the reg register */
+uint8_t ADXL355::read_reg(ADXL355_register_t reg){
+ uint8_t ret_val;
+ adxl355.format(8, _SPI_MODE);
+ cs = false;
+ adxl355.write(reg<<1 | _READ_REG_CMD);
+ ret_val = adxl355.write(_DUMMY_BYTE);
+ cs = true;
+ return ret_val;
+}
+uint16_t ADXL355::read_reg_u16(ADXL355_register_t reg){}
+uint32_t ADXL355::read_reg_u32(ADXL355_register_t reg){}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ADXL35x/ADXL355.h Tue Aug 07 12:49:37 2018 +0000
@@ -0,0 +1,177 @@
+
+#ifndef ADXL355_H_
+#define ADXL355_H_
+
+class ADXL355
+{
+public:
+
+ // -------------------------- //
+ // REGISTERS //
+ // -------------------------- //
+ typedef enum {
+ DEVID_AD = 0x00,
+ DEVID_MST = 0x01,
+ PARTID = 0x02,
+ REVID = 0x03,
+ STATUS = 0x04,
+ FIFO_ENTRIES = 0x05,
+ TEMP2 = 0x06,
+ TEMP1 = 0x07,
+ XDATA3 = 0x08,
+ XDATA2 = 0x09,
+ XDATA1 = 0x0A,
+ YDATA3 = 0x0B,
+ YDATA2 = 0x0C,
+ YDATA1 = 0x0D,
+ ZDATA3 = 0x0E,
+ ZDATA2 = 0x0F,
+ ZDATA1 = 0x10,
+ FIFO_DATA = 0x11,
+ OFFSET_X_H = 0x1E,
+ OFFSET_X_L = 0x1F,
+ OFFSET_Y_H = 0x20,
+ OFFSET_Y_L = 0x21,
+ OFFSET_Z_H = 0x22,
+ OFFSET_Z_L = 0x23,
+ ACT_EN = 0x24,
+ ACT_THRESH_H = 0x25,
+ ACT_THRESH_L = 0x26,
+ ACT_COUNT = 0x27,
+ FILTER = 0x28,
+ FIFO_SAMPLES = 0x29,
+ INT_MAP = 0x2A,
+ SYNC = 0x2B,
+ RANGE = 0x2C,
+ POWER_CTL = 0x2D,
+ SELF_TEST = 0x2E,
+ RESET = 0x2F
+ } ADXL355_register_t;
+
+ // -------------------------- //
+ // REGISTERS - DEFAULT VALUES //
+ // -------------------------- //
+ // Modes - POWER_CTL
+ typedef enum {
+ DRDY_OFF = 0x04,
+ TEMP_OFF = 0x02,
+ STANDBY = 0x00,
+ MEASUREMENT = 0x01
+ } ADXL355_modes_t;
+ // Activate Threshold - ACT_EN
+ typedef enum {
+ ACT_Z = 0x04,
+ ACT_Y = 0x02,
+ ACT_X = 0x01
+ } ADXL355_act_ctl_t;
+ // High-Pass and Low-Pass Filter - FILTER
+ typedef enum {
+ HPFOFF = 0x00,
+ HPF247 = 0x10,
+ HPF62 = 0x20,
+ HPF15 = 0x30,
+ HPF3 = 0x40,
+ HPF09 = 0x50,
+ HPF02 = 0x60,
+ ODR4000HZ = 0x00,
+ ODR2000HZ = 0x01,
+ ODR1000HZ = 0x02,
+ ODR500HZ = 0x03,
+ ODR250HZ = 0x04,
+ ODR125Hz = 0x05,
+ ODR62HZ = 0x06,
+ ODR31Hz = 0x07,
+ ODR15Hz = 0x08,
+ ODR7Hz = 0x09,
+ ODR3HZ = 0x0A
+ } ADXL355_filter_ctl_t;
+ // External timing register - INT_MAP
+ typedef enum {
+ OVR_EN = 0x04,
+ FULL_EN = 0x02,
+ RDY_EN = 0x01
+ } ADXL355_intmap_ctl_t;
+ // External timing register - SYNC
+ typedef enum {
+ EXT_CLK = 0x04,
+ INT_SYNC = 0x00,
+ EXT_SYNC_NO_INT = 0x01,
+ EXT_SYNC_INT = 0x02
+ } ADXL355_sync_ctl_t;
+ // polarity and range - RANGE
+ typedef enum {
+ RANGE2G = 0x01,
+ RANGE4G = 0x02,
+ RANGE8G = 0x03,
+ RANGE10 = 0x00,
+ RANGE20 = 0x02,
+ RANGE40 = 0x03
+ } ADXL355_range_ctl_t;
+ // self test interrupt - INT
+ typedef enum {
+ ST2 = 0x02,
+ ST1 = 0x01
+ } ADXL355_int_ctl_t;
+
+ // -------------------------- //
+ // FUNCTIONS //
+ // -------------------------- //
+ // SPI configuration & constructor
+ ADXL355(PinName cs_pin , PinName MOSI , PinName MISO , PinName SCK );
+ void frequency(int hz);
+ // Low level SPI bus comm methods
+ void reset(void);
+ void write_reg(ADXL355_register_t reg, uint8_t data);
+ void write_reg_u16(ADXL355_register_t reg, uint16_t data);
+ uint8_t read_reg(ADXL355_register_t reg);
+ uint16_t read_reg_u16(ADXL355_register_t reg);
+ uint32_t read_reg_u32(ADXL355_register_t reg);
+ // ADXL general register R/W methods
+ void set_power_ctl_reg(uint8_t data);
+ void set_filter_ctl_reg(ADXL355_filter_ctl_t hpf, ADXL355_filter_ctl_t odr);
+ void set_mode(ADXL355_modes_t mode);
+ void set_clk(ADXL355_sync_ctl_t data);
+ void set_device(ADXL355_range_ctl_t range);
+ uint8_t read_status();
+ // ADXL X/Y/Z/T scanning methods
+ uint32_t scanx();
+ uint32_t scany();
+ uint32_t scanz();
+ uint16_t scant();
+ // ADXL activity methods
+ void set_activity_axis(ADXL355_act_ctl_t axis);
+ void set_activity_cnt(uint8_t count);
+ void set_activity_threshold(uint16_t data_h, uint16_t data_l);
+ void set_inactivity();
+ // ADXL interrupt methods
+ void set_interrupt1_pin(PinName in, ADXL355_intmap_ctl_t mode);
+ void set_interrupt2_pin(PinName in, ADXL355_intmap_ctl_t mode);
+ void enable_interrupt1();
+ void enable_interrupt2();
+ void disable_interrupt1();
+ void disable_interrupt2();
+ void set_polling_interrupt1_pin(uint8_t data);
+ void set_polling_interrupt2_pin(uint8_t data);
+ bool get_int1();
+ bool get_int2();
+ // ADXL FIFO methods
+ uint16_t fifo_read_nr_of_entries();
+ void fifo_setup(uint8_t nr_of_entries);
+ uint32_t fifo_read_u32();
+ uint64_t fifo_scan();
+
+ // ADXL tilt methods
+ // TBD
+private:
+ // SPI adxl355; ///< SPI instance of the ADXL
+ SPI adxl355; DigitalOut cs;
+ const static uint8_t _DEVICE_AD = 0xAD; // contect of DEVID_AD (only-read) register
+ const static uint8_t _RESET = 0x52; // reset code
+ const static uint8_t _DUMMY_BYTE = 0xAA; // 10101010
+ const static uint8_t _WRITE_REG_CMD = 0x00; // write register
+ const static uint8_t _READ_REG_CMD = 0x01; // read register
+ const static uint8_t _READ_FIFO_CMD = 0x23; // read FIFO
+ const static uint8_t _SPI_MODE = 0; // timing scheme
+};
+
+#endif
\ No newline at end of file
--- a/README.md Tue Aug 07 07:20:36 2018 +0000 +++ b/README.md Tue Aug 07 12:49:37 2018 +0000 @@ -1,57 +1,1 @@ -# Getting started with Blinky on mbed OS - -This guide reviews the steps required to get Blinky working on an mbed OS platform. - -Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). - -## Import the example application - -From the command-line, import the example: - -``` -mbed import mbed-os-example-blinky -cd mbed-os-example-blinky -``` - -### Now compile - -Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: - -``` -mbed compile -m K64F -t ARM -``` - -Your PC may take a few minutes to compile your code. At the end, you see the following result: - -``` -[snip] -+----------------------------+-------+-------+------+ -| Module | .text | .data | .bss | -+----------------------------+-------+-------+------+ -| Misc | 13939 | 24 | 1372 | -| core/hal | 16993 | 96 | 296 | -| core/rtos | 7384 | 92 | 4204 | -| features/FEATURE_IPV4 | 80 | 0 | 176 | -| frameworks/greentea-client | 1830 | 60 | 44 | -| frameworks/utest | 2392 | 512 | 292 | -| Subtotals | 42618 | 784 | 6384 | -+----------------------------+-------+-------+------+ -Allocated Heap: unknown -Allocated Stack: unknown -Total Static RAM memory (data + bss): 7168 bytes -Total RAM memory (data + bss + heap + stack): 7168 bytes -Total Flash memory (text + data + misc): 43402 bytes -Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin -``` - -### Program your board - -1. Connect your mbed device to the computer over USB. -1. Copy the binary file to the mbed device. -1. Press the reset button to start the program. - -The LED on your platform turns on and off. - -## Troubleshooting - -If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it. +ADxl355 on the EV-GEAR-EXPANDER1Z
--- a/main.cpp Tue Aug 07 07:20:36 2018 +0000
+++ b/main.cpp Tue Aug 07 12:49:37 2018 +0000
@@ -1,5 +1,25 @@
#include "mbed.h"
+#include "ADXL355.h"
+
+Serial pc(USBTX, USBRX);
+
+ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK); // PMOD port
+
+int main(){
+ pc.baud(9600);
+ pc.printf("SPI ADXL355 and ADXL357 Demo\n");
+ pc.printf("GET device ID\n");
+ uint8_t x;
+ while(1) {
+ x=accl.read_reg(accl.DEVID_AD);
+ printf("id = %x \r\n",x);
+ wait(1.0);
+ }
+}
+
+
+/*
const static uint8_t _WRITE_REG_CMD = 0x0A; // write register
const static uint8_t _READ_REG_CMD = 0x0B; // read register
const static uint8_t _DUMMY_BYTE = 0xAA;
@@ -69,4 +89,4 @@
uint8_t ret_val;
ret_val = adxl362_read_reg(0x00);
return ret_val;
-}
\ No newline at end of file
+}*/
\ No newline at end of file
