multipelxer with adxl345

i use 3 adxl345 with HCF4052B Multiplexer to arduino uno i want to read the value of adxl345 my connection i2c: GND (For 3 adxl345) to Gnd arduino VCC ((For 3 adxl345)) to 3v ardiono scl ((For 3 adxl345) to A5 sda (For 3 adxl345) to A4 cs (For 3 adxl345) is connect to HVF4052B (0y,2y,3y) Y Common of HCF4052B is connect to 3v arduino i want to give 3v to each cs in order to read the value of adxl345 my probelem is the value is of 1 adxl345 and not changed this image of result

//float gravityFactor=9,81;
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"

// I2Cdev and ADXL345 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "ADXL345.h"
// class default I2C address is 0x53
// specific I2C addresses may be passed as a parameter here
// ALT low = 0x53 (default for SparkFun 6DOF board)
// ALT high = 0x1D

int i=0;
int j=0;
int16_t ax, ay, az,bx,by,bz;
double nx,ny,nz,nxx,nyy,nzz;
ADXL345 accel1;
 ADXL345 accel2;
 ADXL345 accel3;
void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    Wire.begin();
    
 accel1.setRange(ADXL345_RANGE_2G);

 // initialize serial communication
    // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
    // it's really up to you depending on your project)
    Serial.begin(9600);

   pinMode(13, OUTPUT);  
  pinMode(10, OUTPUT);    // s0

  pinMode(9, OUTPUT);    // s1
  
  //accel3= ADXL345(0x1E);
    // initialize device
    Serial.println("Initializing I2C devices...");
    accel1.initialize();
    accel2.initialize();
    accel3.initialize();


 //  accel.setTapDetectionXYZ(1);
    // verify connection
    Serial.println("Testing device connections...");
    Serial.println(accel1.testConnection() ? "ADXL345 connection successful" : "ADXL345 connection failed");
accel1.setOffset(0,0,1);

}

void loop() {
digitalWrite(13,HIGH);
//int id=  accel.getDeviceID();
//Serial.println(id);
j=j+1;
  i=i+1;
    // read raw accel measurements from device
    digitalWrite(10,LOW);
digitalWrite(9,LOW);
    accel1.getAcceleration(&ax, &ay, &az);
      
       Serial.print(i);
    Serial.print(" accel 1:\t");
    Serial.print(ax); Serial.print("\t");
    Serial.print(ay); Serial.print("\t");
    Serial.println(az);

delay(5000);
      digitalWrite(10,LOW);
digitalWrite(9,HIGH);

   
    



   
    accel1.getAcceleration(&ax, &ay, &az);
      
       Serial.print(i);
    Serial.print(" accel 1:\t");
    Serial.print(ax); Serial.print("\t");
    Serial.print(ay); Serial.print("\t");
    Serial.println(az);



      digitalWrite(10,HIGH);
digitalWrite(9,HIGH);
 accel1.getAcceleration(&ax, &ay, &az);
      
       Serial.print(i);
    Serial.print(" accel 1:\t");
    Serial.print(ax); Serial.print("\t");
    Serial.print(ay); Serial.print("\t");
    Serial.println(az);


    
    delay(5000);
   
}

any help for what is problem ????

i want to give 3v to each cs in order to read the value of adxl345

Normally, you set the chip select pin LOW to talk to a device. But, that only applies to SPI devices, NOT I2C devices. I2C devices have (to have) unique addresses.

How have you assigned each ADXL345 a unique address?

i don't know how to assigne a unique address for each adxl345 but i want active cs in case the adxl345 work without cs !

danielsemaan: i don't know how to assigne a unique address for each adxl345 but i want active cs in case the adxl345 work without cs !

That's weird logic. It's like saying, I want to take medicine in case I don't get sick.

aarg how i can read the 3 value ?

Please post a schematic diagram.

i don't have a diagram but i want to connect 3 adxl345 to arduino uno and read the value my connection is i2c i have a multiplexer when i connect the 3 adxl345 the ouput value is for one i want read the value of 3 adxl345 i can work to the CS pin ? when CS is set to 1 read the value ?

danielsemaan: i don't have a diagram

Then make one.

sorry but now i can make my diagram

The CS pin on the ADXL345 can not be used in I2C mode. It can only be used for SPI mode.

..and frustratingly, you can't ever turn off I2C mode so it can misinterpret commands on the SPI bus as I2C commands.

But for this application, I would connect the "CS" output coming from the Arduino to the Alt Address pin. Then set all of the ADXL345 addresses to the alternate, except for the one you want to talk to.

This will require testing. It may not check the input on this pin during normal operations. In fact, I've got a couple on a breadboard now - I'll try the experiment.

Yes it works. You can use the alternate address pin like CS when in I2C mode:

  digitalWrite(AddressSelect[i], LOW); 
  readRegister(DATAX0, 6, values);
  digitalWrite(AddressSelect[i], HIGH);

Hello MorganS thank you for help how i can modifier my code in question to read the 3 value ? adxl345 work without connect cs and how i can read value when the cs is connect ?

You have a library which I don't have. I can only guess what's inside it.

If you want to use this scheme instead of the more normal SPI communications then you should only use one library object. Each time you do anything with the library, such as calling the initialize() method, set the "CS" lines yourself. Like my example showed, even though I am using a function I wrote myself instead of a library the principle is the same.

The datasheet explicitly says that you cannot leave the adxl345 CS floating. But to leave random inputs to a chip floating without knowing about them is pretty dumb anyway.

Be sure to allow adequate time for the address selects to settle before you attempt an I2C transaction, and don't change them until it is complete.

I recommend changing your terminology from "CS" to something that is less likely to get you confused as you go on, like "AS"...

Note that in software, you will always use the alternate I2C address.

aarg: Be sure to allow adequate time for the address selects to settle before you attempt an I2C transaction, and don't change them until it is complete.

I thought of that and I tested for it. I expected to have a millisecond delay required. It doesn't seem to need any delay. The nanosecond overhead of calling the read function on the Arduino is enough for the chip to stabilize on the new address.

Some other I2C chips have more complex addressing pins that don't determine the chip's address until after the address byte has begun transmission.