How do I use the Teensy 4.0 SPI feature to communicate with Protocentral's ADS1220

Status
Not open for further replies.

alexander5398

New member
Hello,

I am trying to use a Teensy 4.0 board to get data from an ADS1220 24-bit ADC. When I try to run the code below, the serial terminal only prints one "Hello". It seems like whenever I try to use the Protocentral_ADS1220 object, the program stops running. When I uncomment all the functions with 'adc' in the setup code, nothing prints to the serial monitor.

I have included the pin connections in the comments at the top. I have run this same code with a different arduino board so there shouldn't be anything wrong with it. I know that the Teensyduino library has it's own SPI.h file. Do I need to specify which SPI.h file to use?

Code:
/////////////////////////////////////////////////////////////////////////////////////////
//
//    Demo code for the ADS1220 24-bit ADC breakout board
//
//    Author: Ashwin Whitchurch
//    Copyright (c) 2018 ProtoCentral
//
//    This example gives differential voltage across the AN0 and AN1 pins in mVolts
//
//    Arduino connections:
//
//  |ADS1220 pin label| Pin Function         |Teensy 4.0 Connection|
//  |-----------------|:--------------------:|-----------------:|
//  | DRDY            | Data ready Output pin|  14              |
//  | MISO            | Slave Out            |  12             |
//  | MOSI            | Slave In             |  11             |
//  | SCLK            | Serial Clock         |  15             |
//  | CS              | Chip Select          |  10              |
//  | DVDD            | Digital VDD          |  +3.3V             |
//  | DGND            | Digital Gnd          |  Gnd             |
//  | AN0-AN3         | Analog Input         |  Analog Input    |
//  | AVDD            | Analog VDD           |  -               |
//  | AGND            | Analog Gnd           |  -               |
//
//    This software is licensed under the MIT License(http://opensource.org/licenses/MIT).q
//
//   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
//   NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
//   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
//   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//   For information on how to use, visit https://github.com/Protocentral/Protocentral_ADS1220
//
/////////////////////////////////////////////////////////////////////////////////////////

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

#define PGA 64
#define PGA_GAIN PGA_GAIN_64
#define VREF 2.048                        // Internal reference of 2.048V
#define VFSR VREF/PGA
#define FSR (((long int)1<<23)-1)

#define ADS1220_CS_PIN    10
#define ADS1220_DRDY_PIN  14

#define R_TOP 21.8e3
#define R_BOT 21.6e3

Protocentral_ADS1220 adc;
int32_t adc_data;

float Vout;


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

//    adc.begin(ADS1220_CS_PIN,ADS1220_DRDY_PIN);

//    adc.set_data_rate(DR_20SPS);
//    adc.set_pga_gain(PGA_GAIN);
//    adc.select_mux_channels(MUX_AIN0_AIN1);  //Configure for differential measurement between AIN0 and AIN1
//
//    adc.Start_Conv();  //Start continuous conversion mode
}

void loop()
{

    Serial.println("Hello");
    
    adc_data = adc.Read_WaitForData();

    Serial.println("HEllo");
          
    Vout = (float) ((adc_data * VFSR * 1000) / FSR);     //In  mV 
    
    Serial.println(  String( (float) ( Vout * (R_TOP+R_BOT) / (3300.0 - Vout) ) ) );

 
    delay(100); 
}
 
one thing I can see, is you have commented out the adc.begin line. thats probably needed before the adc.read will work.

as for the rest, have you tried the demo code included with that lib (if there is such)
 
Nothing will print to the serial monitor if I un comment that line. If I use the “adc” object anywhere then it seems to hang, nothing else is printed

This is basically the demo code, with a few minor changes. Like I said, the code works on another board. I think it has something to do with how the Teensy SPI works
 
You might try updating the SPI files that were installed, with the ones that are currently waiting on a Pull Request.
https://github.com/KurtE/SPI/tree/T4_OLD_APIS

This fixed some other similar issues where some code/libraries is not using transactions... I also implemented some of the older APIs that are now depreciated.

Or you could try a simple hack to hopefully get around some of it.
Code:
void setup()
{
    Serial.begin(9600); 
    [COLOR="#FF0000"]SPI.begin();
    SPI.beginTransaction(SPISettings());
    SPI.endTransaction();[/COLOR]

   adc.begin(ADS1220_CS_PIN,ADS1220_DRDY_PIN);
...
Typed in above on fly so could be issues. Also I lets SPISettings default, which I believe is 4mbs, MSBFIRST, SPI_MODE0... It is possible that the library may need different settings.
 
Status
Not open for further replies.
Back
Top