32 channel mux ADG731 switches

Hello, i have a project where i want to use an Arduino UNO card as SPI master that controlled two ADG731 mux 32 channels each. using the two simultaneously, i expect to be able to switch between 24 wires connected to the two mux at the same time.
(a resistance is measured between the first wire and the second, the second and third,... it ends at the twenty fourth)
Here's the script that allow me to only detect the two first wire but can't swith any further.
I don't know precisely which channel there are connected to and if i need to know that.

#include <LiquidCrystal.h>
#include <IRremote.hpp>
#include <SPI.h>
#include <Wire.h>



LiquidCrystal lcd(11, 10, 5, 4, 3, 2);
#define SS 8  //slave select
#define SS1 10
#define e1 3  //engine +
#define e2 4   //engine -
int recption = 12;
long code;
IRrecv irrecv(recption);
decode_results results;


const SPISettings spiSettings(0, MSBFIRST, SPI_MODE1);
// The SPISettings object specifies the SPI peripheral settings.
uint8_t i = 0;
uint8_t j = 0;
int z = 0;
int s = 0;
int pinBouton1 = 5;
int pinBouton2 = 4;
int pinBouton0 = 6;
int pinMoteur = 3;
boolean test1;
boolean test2;
boolean test0;
boolean moteur;


void setup() {
 Serial.begin(9600);
 SPI.begin();
 // Initializes the SPI bus by setting SCK, MOSI, and a user-specified slave-select pin to outputs, MISO to input. SCK is pulled either high or low depending on the configured SPI data mode (default high for SPI_MODE3). Slave-select is pulled high.
 SPI.beginTransaction(spiSettings);
 // Reconfigures the SPI peripheral with the supplied settings. In addition to reconfiguring the SPI peripheral, beginTransaction() also acquires the SPI peripheral lock, blocking other threads from using the selected SPI peripheral until endTransaction() is called.
 irrecv.enableIRIn();  // Start the receiver
 pinMode(SS, OUTPUT);
 pinMode(SS1, OUTPUT);
 pinMode(e2, OUTPUT);
 pinMode(e1, OUTPUT);


 digitalWrite(SS1, HIGH);
 digitalWrite(SS, HIGH);
 analogWrite(e2, 0);
 analogWrite(e1, 0);




 pinMode(pinBouton1, INPUT_PULLUP);
 pinMode(pinBouton2, INPUT_PULLUP);
 pinMode(pinBouton0, INPUT_PULLUP);
 pinMode(pinMoteur, INPUT_PULLUP);
 digitalWrite(SS, LOW);
 SPI.transfer(i);
 //Transfers one byte over the SPI bus, both sending and receiving.Where the parameter val, can is the byte to send out over the SPI bus.Note that you must use the same SPI object as used with SPI.begin() so if you used SPI1.begin() also use SPI1.setDataMode().
 //transfer() acquires the SPI peripheral lock before sending a byte, blocking other threads from using the selected SPI peripheral during the transmission.If you call transfer in a loop, call beginTransaction() function before the loop and endTransaction() after the loop, to avoid having another thread interrupt your SPI operations.led.clear();
 lcd.setCursor(1, 0);
 lcd.print("High :");
 lcd.println(i);
 digitalWrite(SS, HIGH);
 Serial.println(z);
 digitalWrite(SS1, LOW);
 SPI.transfer(j);
 lcd.clear();
 lcd.setCursor(1, 0);
 lcd.print("High :");
 lcd.println(i);
 lcd.setCursor(1, 1);
 lcd.print("LOW :");
 lcd.println(j);
 digitalWrite(SS1, HIGH);
}


void loop() {


 test1 = digitalRead(pinBouton1);
 test2 = digitalRead(pinBouton2);
 test0 = digitalRead(pinBouton0);
 moteur = digitalRead(pinMoteur);
 ////telecommande
 if (irrecv.decode(&results) == 0xBF40FF00) {
   code = results.value;
   irrecv.resume();  // Receive the next value
 }
 ////Partie Moteur//////
 if (moteur == 0 || code == 16712445) {
   delay(100);
   moteur = 1;
   code = 0;
   if (s % 2 == 0) {
     s++;
     analogWrite(e1, 150);
     analogWrite(e2, 0);
     delay(1000);
     analogWrite(e1, 0);
     //analogiWrite (e2, 0);
   } else {
     delay(100);
     moteur = 1;
     s++;
     analogWrite(e1, 0);
     analogWrite(e2, 150);
     delay(1000);
     //analogWrite (el, 0);
     analogWrite(e2, 0);
   }
 }


 ////Patie MUX/////
 if (test0 == 0) {
   delay(100);
   test0 = 1;
   z++;
   i++;
   j++;
   digitalWrite(SS, LOW);
   SPI.transfer(i);
   digitalWrite(SS, HIGH);
   Serial.println(z);
   digitalWrite(SS1, LOW);
   SPI.transfer(j);
   digitalWrite(SS1, HIGH);
 }
}

if you need more information, don't hesitate.

Thank you very much if you help me

I dont think you have the right code here to control your ADG731.

According to is datasheet (page 8) these are the values IHMO you should be send to select the respective channels:

so maybe try something like this with one ADG731 first:
(Compiles, NOT tested!)

#include <SPI.h>

uint8_t ch_select_cmd[34] = {0x40,0x80,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F};

void setup() {
  Serial.begin(115200);
  SPI.begin();         // initialize the SPI library
  pinMode(10, OUTPUT); // set the SS pin as an output
}

void loop() {

  for (uint8_t i = 2; i < 34; ++i) {

    digitalWrite(10, LOW);            // set the SS pin to LOW

    SPI.transfer(ch_select_cmd[i]);      // send a command to select channel

    digitalWrite(10, HIGH);           // set the SS pin HIGH

    // print out currently selected channel (based on command that was sent)
    Serial.print("Channel ");
    Serial.println(i - 1);
    Serial.println(" Selected");
    delay(1000); //Arbitrary delay to for us humans to be able to see the change
  }

  
  //now switch off all channels
  digitalWrite(10, LOW);            // set the SS pin to LOW

  SPI.transfer(ch_select_cmd[1]);      // send a command to select channel

  digitalWrite(10, HIGH);           // set the SS pin HIGH

  Serial.print("All Channel OFF Channel ");

  delay(1000); //Arbitrary delay to for us humans to be able to see the change

}

hope that helps....

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.