Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two ADS1220 modules not working on an Arduino UNO R4 Minima and WiFi #24

Open
wollewald opened this issue Jan 7, 2025 · 0 comments
Open

Comments

@wollewald
Copy link

Hi,

there is a strange issue when using two ADS1220 modules controlled by an Arduino UNO R4 Minima or WiFi. The two devices are attached correctly to the Arduino.

I have a applied the following sketch:

#include "Protocentral_ADS1220.h"
#include <SPI.h>

#define PGA 1                // Programmable Gain, confirm that the same as set_pga_gain
#define VREF 2.048            // Internal reference of 2.048V
#define VFSR VREF/PGA
#define FSR (((long int)1<<23)-1)

#define ADS1220_CS_1_PIN    7
#define ADS1220_DRDY_1_PIN  2
#define ADS1220_CS_2_PIN    6
#define ADS1220_DRDY_2_PIN  3

Protocentral_ADS1220 pc_ads1220_1;
Protocentral_ADS1220 pc_ads1220_2;

int32_t adc_data;
volatile bool drdyIntrFlag_1 = false;
volatile bool drdyIntrFlag_2 = false;

void drdyInterruptHndlr_1(){
  drdyIntrFlag_1 = true;
}

void drdyInterruptHndlr_2(){
  drdyIntrFlag_2 = true;
}

void enableInterruptPins(){
  attachInterrupt(digitalPinToInterrupt(ADS1220_DRDY_1_PIN), drdyInterruptHndlr_1, FALLING);
//   attachInterrupt(digitalPinToInterrupt(ADS1220_DRDY_2_PIN), drdyInterruptHndlr_2, FALLING);
}

void setup()
{
  Serial.begin(115200);

  // Avoid intializazion of the wrong module
  pinMode(ADS1220_CS_1_PIN, OUTPUT);
  digitalWrite(ADS1220_CS_1_PIN, HIGH); // Inicialmente CS inactivo 
  pinMode(ADS1220_CS_2_PIN, OUTPUT);
  digitalWrite(ADS1220_CS_2_PIN, HIGH); // Inicialmente CS inactivo

  // Set up ADS1220 #1
  pc_ads1220_1.begin(ADS1220_CS_1_PIN,ADS1220_DRDY_1_PIN);
  pc_ads1220_1.set_data_rate(DR_20SPS);
  pc_ads1220_1.set_pga_gain(PGA_GAIN_1);
  pc_ads1220_1.select_mux_channels(MUX_AIN0_AIN1);  //Configure for differential measurement between AIN0 and AIN1
  pc_ads1220_1.set_conv_mode_continuous();          //Set continuous conversion mode
  pc_ads1220_1.Start_Conv();  //Start continuous conversion mode

  // Set up ADS1220 #2 
  pc_ads1220_2.begin(ADS1220_CS_2_PIN,ADS1220_DRDY_2_PIN);
//   pc_ads1220_2.set_data_rate(DR_20SPS);
//   pc_ads1220_2.set_pga_gain(PGA_GAIN_1);
//   pc_ads1220_2.select_mux_channels(MUX_AIN0_AIN1);  //Configure for differential measurement between AIN0 and AIN1
//   pc_ads1220_2.set_conv_mode_continuous();          //Set continuous conversion mode
//   pc_ads1220_2.Start_Conv();  //Start continuous conversion mode

  enableInterruptPins();
}

void loop()
{
  if(drdyIntrFlag_1){
    drdyIntrFlag_1 = false;
    adc_data=pc_ads1220_1.Read_Data_Samples();
    float Vout = (float)((adc_data*VFSR*1000)/FSR);     //In  mV
    delay(1000);
    Serial.print("Vout #1 in mV : ");
    Serial.println(Vout);     
  }
//   if(drdyIntrFlag_2){
//     drdyIntrFlag_2 = false;
//     adc_data=pc_ads1220_2.Read_Data_Samples();
//     float Vout = (float)((adc_data*VFSR*1000)/FSR);     //In  mV
//     delay(1000);
//     Serial.print("Vout #2 in mV : ");
//     Serial.println(Vout);     
//   }
}

The sketch should display correct voltages (0 - 2.048 V) attached to AIN0/AIN1 for the ADS1220 #1. But the result is wrong. The same sketch works well with the Arduino UNO R3. If you comment out just that one line, you will get a correct result:

 pc_ads1220_1.begin(ADS1220_CS_1_PIN,ADS1220_DRDY_1_PIN);

If you uncomment all relevant lines for ADS1220 #2 and run the sketch on an Arduino UNO R3, you will get correct results for both the ADS1220 #1 and #2. That makes me confident that there is no issue with the wiring which was exactly the same for the trials with the Arduino UNO R4.

To be be honest I did not find the issue myself. I have an own library for the ADS1220 and a user found exactly the same problem with my one:
https://github.com/wollewald/ADS1220_WE / wollewald/ADS1220_WE#5
I have spent lots of hours trying to find the root cause but failed.

It is basically possible to communicate with the two ADS1220 devices when using an Arduino UNO R4. For this, I have tried to write data in config 0 register of the two devices an then read it back. This works fine:

#include <SPI.h>

#define ADS1220_1_CS_PIN    7   // Chip Select
#define ADS1220_2_CS_PIN    5   //
SPISettings mySPISettings(4000000, MSBFIRST, SPI_MODE1);

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println("Initializing ADS1220 #1 and #2 ...");
  SPI.begin();

  // Avoid intializazion of the wrong module
  pinMode(ADS1220_1_CS_PIN, OUTPUT);
  digitalWrite(ADS1220_1_CS_PIN, HIGH); 
  pinMode(ADS1220_2_CS_PIN, OUTPUT);
  digitalWrite(ADS1220_2_CS_PIN, HIGH); 

  delay(100);

  // write/read some dummy values into/from Config 0 register
  writeConfig0(ADS1220_1_CS_PIN); // write into ADS1220 #1
  readADS1220(ADS1220_1_CS_PIN);  // read from ADS1220 #1
  writeConfig0(ADS1220_2_CS_PIN); // write into ADS1220 #2
  readADS1220(ADS1220_2_CS_PIN);  // read from ADS1220 #2
  readADS1220(ADS1220_1_CS_PIN);  // read from ADS1220 #1 (double check)
}

void loop() {
  delay(1000);
}

void writeConfig0(int csPin) {
  // force Reset
  SPI.beginTransaction(mySPISettings);
  digitalWrite(csPin, LOW); // activate CS
  SPI.transfer(0x06); // Reset command
  digitalWrite(csPin, HIGH); // deactivate CS
  SPI.endTransaction();
  delayMicroseconds(50); 
  
  // write something into Config 0 reg. 
  SPI.beginTransaction(mySPISettings);
  digitalWrite(csPin, LOW); //  activate CS
  SPI.transfer(0x40 | (0x00 << 2)); 
  if(csPin == ADS1220_1_CS_PIN){
    SPI.transfer(0x03); // PGA bypass and gain = 2
  }
  else{
    SPI.transfer(0x01);  // PGA bypass 
  }
  digitalWrite(csPin, HIGH); // deactivate CS
  SPI.endTransaction();
}

void readADS1220(int csPin){
  SPI.beginTransaction(mySPISettings);
  digitalWrite(csPin, LOW); //  activate CS
  SPI.transfer(0x20 | (0x00 << 2)); 
  byte config0 = SPI.transfer(0x00); 
  digitalWrite(csPin, HIGH); // deactivate CS
  SPI.endTransaction();
  if(csPin == ADS1220_1_CS_PIN){
    Serial.print("Config Register 0 (ADS1220 #1): 0x");
  }
  else {
    Serial.print("Config Register 0 (ADS1220 #2): 0x"); 
  }
  Serial.println(config0, HEX);
}

This works correctly on the UNO R3 and R4.

Do you have any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant