Using Protocentral ADS1220 with Teensy

Status
Not open for further replies.

Snofoxx

Member
I am trying to use Protocentral's ADS1220 24-bit analog to converter (link below) with a Teensy 3.6.

https://www.protocentral.com/analog-adc-boards/773-ads1220-24-bit-4-channel-low-noise-adc-breakout-board.html

I'm having trouble changing some of the default settings of the device (sampling rate, operating mode, reference voltage, etc.). I am using Teensyduino to use modified versions of the example code and library provided by Protocentral that were created for Arduino. The code I am using is below and I have attached the modified version of the library that I am using here (View attachment Protocentral_ADS1220.cpp, View attachment Protocentral_ADS1220.h). I modified it by adding functions to change some additional settings that the original version didn't have.

Code:
/*************************************************************
  |ads1220 pin label| Pin Function         |Teensy  Connection|
  |-----------------|:--------------------:|-----------------:|
  | DRDY            | Data ready Output pin|  6               |
  | MISO            | Slave Out            |  12 / MISO0      |
  | MOSI            | Slave In             |  11 / MOSI0      |
  | SCLK            | Serial Clock         |  13 / SCK0       |
  | CS              | Chip Select          |  10 / CS0        |
  | DVDD            | Digital VDD          |  +3.3V           |
  | DGND            | Digital Gnd          |  Gnd             |
  | AN0-AN3         | Analog Input         |  Analog Input    |
  | AVDD            | Analog VDD           |  -               |
  | AGND            | Analog Gnd           |  -               |
*************************************************************/

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

#define PGA 1                 // Programmable Gain = 1
#define VREF 2.048            // Internal reference of 2.048V
#define VFSR VREF/PGA
#define FSR (((long int)1<<23)-1)

volatile byte MSB;
volatile byte data;
volatile byte LSB;
volatile byte *SPI_RX_Buff_Ptr;

long int bit32;
long int bit24;

Protocentral_ADS1220 ADS1220;

#define DAC0(a) *(volatile int16_t *)&(DAC0_DAT0L)=a

// 1 V * (4095 / 3.3 V) = 1241
int shalf = 1241; // 1241 / 2
int off = 1241;
float i;

void setup() {
  pinMode(ADS1220_CS_PIN, OUTPUT);
  pinMode(ADS1220_DRDY_PIN, INPUT);

  analogReadResolution(13); // 0 to 8191
  analogWriteResolution(12); // 0 to 4095
  SIM_SCGC2 |= SIM_SCGC2_DAC0;
  DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS; // 3.3V VDDA is DACREF_2

  ADS1220.begin();

  // Functions I added:
  //  ADS1220.set_read_mode(MUX_AIN0); // Change to differential or single-ended readings
  //  ADS1220.set_op_mode(OM_TURBO); // Change operating mode
  //  ADS1220.set_volt_ref(VR_REFP); // Change voltage reference used
  //  ADS1220.set_filt(FILT_NONE); // Change filter settings

  // Built-in functions that came with library:
  //  ADS1220.set_data_rate(DR_45SPS);
  //  ADS1220.set_pga_gain(PGA_GAIN_2);
}

void loop() {
  SPI_RX_Buff_Ptr = ADS1220.Read_Data();

  if (ADS1220.NewDataAvailable == true) {
    ADS1220.NewDataAvailable = false;

    MSB = SPI_RX_Buff_Ptr[0];
    data = SPI_RX_Buff_Ptr[1];
    LSB = SPI_RX_Buff_Ptr[2];

    bit24 = MSB;
    bit24 = (bit24 << 8) | data;
    bit24 = (bit24 << 8) | LSB; // Converting 3 bytes to a 24 bit int

    bit24 = ( bit24 << 8 );
    bit32 = ( bit24 >> 8 ); // Converting 24 bit two's complement to 32 bit two's complement

    float Vout = (float)((bit32 * VFSR) / FSR); //In  V
    float Vadj = 2.0 * (Vout + 2.05);
    int A = analogRead(9);
    float V = A / 8191.0 * 3.3;

    Serial.print(Vadj);
    Serial.print('\t');
    Serial.println(V);

    int s = shalf * sin(i) + off;
    DAC0(s);
    i = i + 3.14 / 32;
  }
}

When I run this code with all the functions used to change settings commented out it works fine. However, once I start uncommenting some of the functions to change settings it no longer runs. When I try to use the functions that came with the original library, the code compiles fine but nothing shows up in the serial monitor once the code has uploaded. When I try to use one of the functions I added I get a compiling error. For example when I use the function ADS1220.set_op_mode(OM_TURBO); I get the following error:


C:\Users\Susie\Documents\Arduino\myProtocentral/myProtocentral.ino:54: undefined reference to `Protocentral_ADS1220::set_op_mode(int)'

collect2.exe: error: ld returned 1 exit status

Using library Protocentral_ADS1220-master in folder: C:\Users\Susie\Documents\Arduino\libraries\Protocentral_ADS1220-master (legacy)
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI
Error compiling for board Teensy 3.6.


When I use the original version of the library I have the same problem. It works as long as I don't use any of the functions to change the settings. I tried using a very similar code and the same modified library with an Arduino Uno and it works fine, leading me to believe that the problem might be related to differences between coding for Teensy and Arduino, but I don't really know what the problem could be.

Any help would be appreciated.
 
Status
Not open for further replies.
Back
Top