johnwasser:
ARDUINO pins 14-17 a.k.a. A0-A3. Yes, they are pins 23-26 on the ATmega chip.Hardware SPI is on ARDUINO pins 10-13 which are pins 16-19 on the ATmega.
If you are going to use the Arduino libraries you should probably get used to calling the pins by their Arduino numbers to avoid confusion. You can learn more about the naming here: Arduino Pins - Google Drive
hi John....sorry for use up your time for this. In the progress i edit my code till like this:
setup:
char adxl345_read(char address);
int ledPin = 2;
#define ACCEL_CS A0
#define ACCEL_SCK A1
#define ACCEL_DI A2
#define ACCEL_DO A3
#define DATAX0 0x32 //X-Axis Data 0
#define DATAX1 0x33 //X-Axis Data 1
#define DATAY0 0x34 //Y-Axis Data 0
#define DATAY1 0x35 //Y-Axis Data 1
#define DATAZ0 0x36 //Z-Axis Data 0
#define DATAZ1 0x37 //Z-Axis Data 1
#define SELECT_ACCEL() digitalWrite(ACCEL_CS, LOW)
#define UNSELECT_ACCEL() digitalWrite(ACCEL_CS, HIGH)
#define CLOCK_HIGH() digitalWrite(ACCEL_SCK, HIGH)
#define CLOCK_LOW() digitalWrite(ACCEL_SCK, LOW)
#include <SPI.h>
void setup(){
SPI.begin();
Serial.begin(57600);
pinMode(ledPin, OUTPUT);
}
read function:
char adxl345_read(char register_address){
char read_address=0x80 | register_address;
char register_value=0;
char temp = 0;
CLOCK_HIGH();
SELECT_ACCEL(); //Lower CS pin.
if (register_value!=temp)
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000);
}
else{
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); } // waits for a second
for(int bit=7; bit>=0; bit--){
CLOCK_LOW();
digitalWrite(ACCEL_DI, read_address & (1<<bit));
delayMicroseconds(1);
CLOCK_HIGH();
delayMicroseconds(1);
}
for(int bit=7; bit>=0; bit--){
CLOCK_LOW();
delayMicroseconds(1);
CLOCK_HIGH();
delayMicroseconds(1);
register_value |= digitalRead(ACCEL_DI)<<bit;
}
UNSELECT_ACCEL();
temp = register_value;
return register_value;
}
Loop:
void loop(){
adxl345_read(DATAX0);
}
same i use ledpin to indicate the availability of the register_value....but still no given any response....following the reference that u gave:
i connect the A0-A3 to pin 11-13 (while pin 10 is not for SPI right?)...so is there any error?
Again, thanks for sparing your time on me. Appreciate so much