base program for tilt measurement

Dependencies:   COG4050_ADT7420 ADXL362

Fork of COG4050_adxl355_adxl357-ver2 by ADI_CAC

Committer:
vtoffoli
Date:
Tue Aug 07 12:49:37 2018 +0000
Revision:
2:14dc1ec57f3b
Child:
3:ee052fdb4331
draft

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtoffoli 2:14dc1ec57f3b 1 #include <stdint.h>
vtoffoli 2:14dc1ec57f3b 2 #include "mbed.h"
vtoffoli 2:14dc1ec57f3b 3 #include "ADXL355.h"
vtoffoli 2:14dc1ec57f3b 4
vtoffoli 2:14dc1ec57f3b 5
vtoffoli 2:14dc1ec57f3b 6 //DigitalOut(cs); ///< DigitalOut instance for the chipselect of the ADXL
vtoffoli 2:14dc1ec57f3b 7 //DigitalOut int1; ///< DigitalOut instance for the chipselect of the ADXL
vtoffoli 2:14dc1ec57f3b 8 //DigitalOut int2; ///< DigitalOut instance for the chipselect of the ADXL
vtoffoli 2:14dc1ec57f3b 9
vtoffoli 2:14dc1ec57f3b 10 ADXL355::ADXL355(PinName cs_pin, PinName MOSI, PinName MISO, PinName SCK): adxl355(MOSI, MISO, SCK), cs(cs_pin){
vtoffoli 2:14dc1ec57f3b 11 cs = 1;
vtoffoli 2:14dc1ec57f3b 12 adxl355.format(8,_SPI_MODE);
vtoffoli 2:14dc1ec57f3b 13 adxl355.lock();
vtoffoli 2:14dc1ec57f3b 14 }
vtoffoli 2:14dc1ec57f3b 15
vtoffoli 2:14dc1ec57f3b 16 /** SPI bus frequency */
vtoffoli 2:14dc1ec57f3b 17 void ADXL355::frequency(int hz){
vtoffoli 2:14dc1ec57f3b 18 adxl355.frequency(hz);
vtoffoli 2:14dc1ec57f3b 19 }
vtoffoli 2:14dc1ec57f3b 20
vtoffoli 2:14dc1ec57f3b 21 /** Software resets */
vtoffoli 2:14dc1ec57f3b 22 void ADXL355::reset(void){
vtoffoli 2:14dc1ec57f3b 23 adxl355.format(8, _SPI_MODE);
vtoffoli 2:14dc1ec57f3b 24 cs = false;
vtoffoli 2:14dc1ec57f3b 25 // Writing Code 0x52 (representing the letter, R, in ASCII or unicode) to this register immediately resets the ADXL362.
vtoffoli 2:14dc1ec57f3b 26 write_reg(RESET, _RESET);
vtoffoli 2:14dc1ec57f3b 27 cs = true;
vtoffoli 2:14dc1ec57f3b 28 }
vtoffoli 2:14dc1ec57f3b 29
vtoffoli 2:14dc1ec57f3b 30 /** Writes the reg register with data */
vtoffoli 2:14dc1ec57f3b 31 void ADXL355::write_reg(ADXL355_register_t reg, uint8_t data){
vtoffoli 2:14dc1ec57f3b 32 adxl355.format(8, _SPI_MODE);
vtoffoli 2:14dc1ec57f3b 33 cs = false;
vtoffoli 2:14dc1ec57f3b 34 adxl355.write(reg<<1 | _WRITE_REG_CMD);
vtoffoli 2:14dc1ec57f3b 35 adxl355.write(data);
vtoffoli 2:14dc1ec57f3b 36 cs = true;
vtoffoli 2:14dc1ec57f3b 37 }
vtoffoli 2:14dc1ec57f3b 38 void ADXL355::write_reg_u16(ADXL355_register_t reg, uint16_t data){}
vtoffoli 2:14dc1ec57f3b 39
vtoffoli 2:14dc1ec57f3b 40 /** Reads the reg register */
vtoffoli 2:14dc1ec57f3b 41 uint8_t ADXL355::read_reg(ADXL355_register_t reg){
vtoffoli 2:14dc1ec57f3b 42 uint8_t ret_val;
vtoffoli 2:14dc1ec57f3b 43 adxl355.format(8, _SPI_MODE);
vtoffoli 2:14dc1ec57f3b 44 cs = false;
vtoffoli 2:14dc1ec57f3b 45 adxl355.write(reg<<1 | _READ_REG_CMD);
vtoffoli 2:14dc1ec57f3b 46 ret_val = adxl355.write(_DUMMY_BYTE);
vtoffoli 2:14dc1ec57f3b 47 cs = true;
vtoffoli 2:14dc1ec57f3b 48 return ret_val;
vtoffoli 2:14dc1ec57f3b 49 }
vtoffoli 2:14dc1ec57f3b 50 uint16_t ADXL355::read_reg_u16(ADXL355_register_t reg){}
vtoffoli 2:14dc1ec57f3b 51 uint32_t ADXL355::read_reg_u32(ADXL355_register_t reg){}