From 56e4e3a3478ee9ff0bee3b01820cfe919f0454e6 Mon Sep 17 00:00:00 2001 From: ladyada Date: Mon, 10 Dec 2012 15:55:17 -0500 Subject: [PATCH] added SPI - tested works --- Adafruit_ADXL345.cpp | 101 +++++++++++++++++++++++++++++++++++-------- Adafruit_ADXL345.h | 7 +++ 2 files changed, 89 insertions(+), 19 deletions(-) diff --git a/Adafruit_ADXL345.cpp b/Adafruit_ADXL345.cpp index ad0b98c..c25ddd1 100644 --- a/Adafruit_ADXL345.cpp +++ b/Adafruit_ADXL345.cpp @@ -55,16 +55,44 @@ static void i2cwrite(uint8_t x) { #endif } + + + +/**************************************************************************/ +/*! + @brief Abstract away SPI receiver & transmitter +*/ +/**************************************************************************/ +static uint8_t spixfer(uint8_t clock, uint8_t miso, uint8_t mosi, uint8_t data) { + uint8_t reply = 0; + for (int i=7; i>=0; i--) { + reply <<= 1; + digitalWrite(clock, LOW); + digitalWrite(mosi, data & (1<