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