base program for tilt measurement

Dependencies:   COG4050_ADT7420 ADXL362

Fork of COG4050_adxl355_adxl357-ver2 by ADI_CAC

ADXL35x/ADXL355.cpp

Committer:
vtoffoli
Date:
2018-08-07
Revision:
2:14dc1ec57f3b
Child:
3:ee052fdb4331

File content as of revision 2:14dc1ec57f3b:

#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){}