Skip to content

Addition of FIFO Control and Status #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/SparkFun_ADXL345.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,3 +819,34 @@ void print_byte(byte val){
Serial.print(val >> i & 1, BIN);
}
}

/********************** FIFO Control and Status *********************/
/* Activates FIFO Modes */
void ADXL345::setFIFOMode(String FIFOMode) {
if (FIFOMode == "FIFO") {
writeTo(ADXL345_FIFO_CTL, 95);
} else if (FIFOMode == "Stream") {
writeTo(ADXL345_FIFO_CTL, 159);
} else if(FIFOMode == "Trigger") {
writeTo(ADXL345_FIFO_CTL, 223);
} else { //Bypass Mode
writeTo(ADXL345_FIFO_CTL, 31);
}
}

byte ADXL345::getFIFOMode() {
byte control = 0;
for(int i=0; i<8; i++) {
control |= getRegisterBit(ADXL345_FIFO_CTL, i) << i;
}
return control;
}

//returns number of data values stored in FIFO
byte ADXL345::getFIFOStatus() {
byte numEntries = 0;
for(int i=0; i<6; i++) {
numEntries |= getRegisterBit(ADXL345_FIFO_STATUS, i) << i;
}
return numEntries;
}
4 changes: 4 additions & 0 deletions src/SparkFun_ADXL345.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class ADXL345
void setJustifyBit(bool justifyBit);
void printAllRegister();

void setFIFOMode(String FIFOMode);
byte getFIFOMode();
byte getFIFOStatus();

private:
void writeTo(byte address, byte val);
void writeToI2C(byte address, byte val);
Expand Down