Go Down

Topic: How to read register value from ADXL345 Eval board? (Read 3 times) previous topic - next topic

tlslaj0417



A0-A3 u mean is ADC0 till ADC3??(pin 23-26)...because pins 14-17 is for SPI right?....correct me if i am wrong...thanks


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: https://spreadsheets.google.com/spreadsheet/pub?key=0AtfNMvfWhA_ccnRId19SNmVWTDE0MEtTOV9HOEdQa0E&gid=0


thanks for good reference..i will refer it when i calling the pins. and now i use the code u provided to me. as you said:
#define ACCEL_CS   A0
#define ACCEL_SCK   A1
#define ACCEL_DI           A2
#define ACCEL_DO   A3

then which pins i should connect to with all these 4 pins?or because of soft connection. i no need to connect it through any hardware?i just define it with these four pins?

tlslaj0417



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: https://spreadsheets.google.com/spreadsheet/pub?key=0AtfNMvfWhA_ccnRId19SNmVWTDE0MEtTOV9HOEdQa0E&gid=0


hi John....sorry for use up your time for this. In the progress i edit my code till like this:
setup:
Code: [Select]

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:
Code: [Select]

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:
Code: [Select]

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:
https://spreadsheets.google.com/spreadsheet/pub?key=0AtfNMvfWhA_ccnRId19SNmVWTDE0MEtTOV9HOEdQa0E&gid=0

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 :)

johnwasser

Probably need:
Code: [Select]

    pinMode(ACCEL_CS, OUTPUT);
    pinMode(ACCEL_SCK, OUTPUT);
    pinMode(ACCEL_DI, OUTPUT);
    pinMode(ACCEL_DO, INPUT);


You don't seem to include any output in your sketch so I don't understand how you detect if it is working or not.

You can remove references to the SPI library since the adxl345_read() function does software SPI.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

tlslaj0417

#13
Mar 22, 2012, 02:33 pm Last Edit: Mar 22, 2012, 03:00 pm by tlslaj0417 Reason: 1

Probably need:
Code: [Select]

    pinMode(ACCEL_CS, OUTPUT);
    pinMode(ACCEL_SCK, OUTPUT);
    pinMode(ACCEL_DI, OUTPUT);
    pinMode(ACCEL_DO, INPUT);


You don't seem to include any output in your sketch so I don't understand how you detect if it is working or not.

You can remove references to the SPI library since the adxl345_read() function does software SPI.


while i am testing my circuit...would u mind to tell me what is the exact of software SPI and hardware SPI???software is that mean that is not exact hardware connection???..thanks

Plus: i do output to test it is working or not..i test with light up a LED...:)
i test it if the register value change all the time thats mean register != temp (not equal to the value before) then the LED is light up.
Code: [Select]

if (register_value!=temp)
            {
              digitalWrite(ledPin, HIGH);   // sets the LED on
              delay(1000);
             }


tlslaj0417

Hi, i follow your advise, add all these
    pinMode(ACCEL_CS, OUTPUT);
    pinMode(ACCEL_SCK, OUTPUT);
    pinMode(ACCEL_DI, OUTPUT);
    pinMode(ACCEL_DO, INPUT);

but still no giving any output.... :~...really stuck now...

Go Up