Cn0391 Code interferes with Spi GFX library how to solve?

Dear support from analog devices.

by using the cn0391 code I discovered that it interferes with the GFx tft Library. How can I first read out the adc and then afterwards access the GFx library without a conflict?

  • 0
    •  Analog Employees 
    on Jul 14, 2020 1:44 PM 4 months ago

    Hi,

    Can you tell me more information on what you are doing?  What CN0391 code are you referencing?(ADICUP or Arduino)  What processor are you running your application on?  What does the physical setup look like?(can you send a picture)  I'm not familiar with the GFx Library do you have a link to that software library?  Also could you send a copy of the code you are trying to run with the CN0391 and the GFx library integrated?

  • The conversion times are as follows:
      ----------------------------------------
      | Mode      | Tconv (ms) | Fconv (Sps) |
      +-----------+------------+-------------+
      | LowPower  | 652        | 1.534       |
      | MidPower  | 330        | 3.030       |
      | FullPower | 90         | 11.11       |
      ----------------------------------------

      created 2018
      by epsilonrt https://github.com/epsilonrt

      This example code is in the public domain.

      github.com/.../examples
    */
    #include <SPI.h>
    #include <ad7124.h>
    #include "Adafruit_GFX.h"
    #include "HX8357_t3n.h"
    #define TFT_DC  9
    #define TFT_CS 10
    #define TFT_RST -1
    #define AD7124_CS 8
    #define AD7124_SPEED 2000000 // 2mhz?
    Ad7124Chip strainADC;
    #define TS_MINX 3800
    #define TS_MAXX 100
    #define TS_MINY 100
    #define TS_MAXY 3750


    HX8357_t3n tft = HX8357_t3n(TFT_CS, TFT_DC, TFT_RST);

    const double Gain = 16;
    const double Rf = 5.11E3;
    const long Zero = 1L << 23;
    const long FullScale = 1L << 24;


    long SBraw[7];
    double SBvolt[7];
    long dataWord;
    byte statusWord;
    byte ch;
    /* constants ================================================================ */
    int filterWord = 100;

    // Sample Speed Setting (Full Power Sinc3 Filter Mode)
    //  FW  |  SPS  |  SPS/Ch
    //  600 |    6  |     1
    //  100 |   60  |    10
    //   40 |  156  |    26
    //   20 |  300  |    50


    SPISettings settingsAD7124(2000000, MSBFIRST, SPI_MODE1);
    SPISettings settingsTFT(16000000, LSBFIRST, SPI_MODE3);


    #define TS_MINX 3800
    #define TS_MAXX 100
    #define TS_MINY 100
    #define TS_MAXY 3750


    /* public variables ========================================================= */
    Ad7124Chip adc;

    /* internal public functions ================================================ */

    // -----------------------------------------------------------------------------
    void setup() {

        pinMode(AD7124_CS, OUTPUT);
      pinMode(TFT_CS, OUTPUT);
     
      SPI.begin();

         //Initialize serial and wait for port to open:
      Serial.begin (38400);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }

      // prints title with ending line break
      Serial.println ("AD7124 Voltmeter");


     
      digitalWrite(AD7124_CS,LOW);
      SPI.beginTransaction(settingsAD7124);
      // Initializes the AD7124 device, the pin /CS is pin 10 (/SS)
      // Initializes the AD7124 device, the pin /CS is pin 10 (/SS)
     // Loop until ADC responds
      int state = strainADC.begin(AD7124_CS);
      while (state < 0) {
        Serial.println(state);
        Serial.println ("Failed");
        delay(100);
        state = strainADC.begin(AD7124_CS);
      }

      // Configuring ADC in Full Power Mode & Continuous Mode (Prevents sleep mode)
      strainADC.setAdcControl(Ad7124::ContinuousMode, Ad7124::FullPower, true);

      strainADC.setMode(Ad7124::ContinuousMode);

      // Configure Channel 0
      strainADC.setConfig(0, Ad7124::RefInternal, Ad7124::Pga1, true);
      strainADC.setConfigFilter(0, Ad7124::Sinc3Filter, filterWord);
      strainADC.setChannel(0, 0, Ad7124::AIN3Input, Ad7124::AIN2Input, true);
     
      // Configure Channel 1
      strainADC.setConfig(1, Ad7124::RefInternal, Ad7124::Pga1, true);
      strainADC.setConfigFilter(1, Ad7124::Sinc3Filter, filterWord);
      strainADC.setChannel(1, 1, Ad7124::AIN5Input, Ad7124::AIN4Input, true);
     
      // Configure Channel 2
      strainADC.setConfig(2, Ad7124::RefInternal, Ad7124::Pga1, true);
      strainADC.setConfigFilter(2, Ad7124::Sinc3Filter, filterWord);
      strainADC.setChannel(2, 2, Ad7124::AIN7Input, Ad7124::AIN6Input, true);
     
      // Configure Channel 3
      strainADC.setConfig(3, Ad7124::RefInternal, Ad7124::Pga1, true);
      strainADC.setConfigFilter(3, Ad7124::Sinc3Filter, filterWord);
      strainADC.setChannel(3, 3, Ad7124::AIN9Input, Ad7124::AIN8Input, true);
     
      // Configure Channel 4
      strainADC.setConfig(4, Ad7124::RefInternal, Ad7124::Pga1, true);
      strainADC.setConfigFilter(4, Ad7124::Sinc3Filter, filterWord);
      strainADC.setChannel(4, 4, Ad7124::AIN11Input, Ad7124::AIN10Input, true);
     
      // Configure Channel 5
      strainADC.setConfig(5, Ad7124::RefInternal, Ad7124::Pga1, true);
      strainADC.setConfigFilter(5, Ad7124::Sinc3Filter, filterWord);
      strainADC.setChannel(5, 5, Ad7124::AIN13Input, Ad7124::AIN12Input, true);

      strainADC.enableChannel(0,true);
      strainADC.enableChannel(1,true);
      strainADC.enableChannel(2,true);
      strainADC.enableChannel(3,true);
      strainADC.enableChannel(4,true);
      strainADC.enableChannel(5,true);
      strainADC.enableChannel(6,false);
      strainADC.enableChannel(7,false);

      delay(100);

        digitalWrite (AD7124_CS, HIGH);// setting the CS Pin high
        SPI.endTransaction();
      digitalWrite(TFT_CS,LOW);

      tft.begin();
      tft.println("Hello World!");
    }

    // -----------------------------------------------------------------------------
    void loop()
    {
        digitalWrite(AD7124_CS,LOW);
            SPI.beginTransaction(settingsAD7124);
       for (int i = 1; i <= 6; i++) {
        strainADC.waitEndOfConversion(100);
        dataWord = strainADC.getData();
        ch = strainADC.currentChannel();
     
        // check RDY bit
        if (ch >= 0) {
          SBraw[ch + 1] = dataWord;
          SBvolt[ch] = Ad7124Chip::toVoltage(SBraw[ch], 1, 2.5, true);
        }
      }

       
      Serial.print("$");
      for (int i = 1; i <= 6; i++) {
        Serial.print(",");
        Serial.print(SBvolt[i]);
      }
        Serial.println("");
      tft.fillScreen(HX8357_BLACK);
      unsigned long start = micros();
      tft.setTextColor(HX8357_WHITE);  tft.setTextSize(1);
      tft.println("Hello World!");


    }

  • I also sometimes get a -2 as return value on the serial monitor...

    why is this?

  • lower filter words like 20,40, dont work. why is this?, i tried changing some delays, but all show a -2.