Giter VIP home page Giter VIP logo

Comments (5)

eriknyquist avatar eriknyquist commented on August 15, 2024

Hi @claudiaAl, this is difficult to answer since we can't see most of the reads/writes you're doing to ADC_CTRL. Can you please post a complete, verifiable example? i.e. an example that I can copy/paste into my own IDE and run myself.

from arduinocore-arc32.

claudiaAl avatar claudiaAl commented on August 15, 2024

Absolutely! My apologies :-)

#include <CurieTimerOne.h>
#include <SPI.h>

#define ATP_BLE_INT     5

uint32_t creg, saved;

void adc_normal_wo_calib_REFERENCE(){
      /* perform power up to "Normal mode w/o calibration" cycle if not already there */
    if( (creg & ADC_MODE_MASK) != ADC_NORMAL_WO_CALIB){

        /* Protect AR_IO_CREG_MST0_CTRL using lock and unlock of interruptions */
        saved = interrupt_lock();
        /* Read current CREG master */
        creg = READ_ARC_REG(AR_IO_CREG_MST0_CTRL);
        creg &= ~(ADC_MODE_MASK);
        /* request ADC to go to Standby mode */
        creg |= ADC_STANDBY | ADC_CLOCK_GATE;
        WRITE_ARC_REG(creg, AR_IO_CREG_MST0_CTRL);
        interrupt_unlock(saved);
        /* Poll CREG Slave 0 for Power Mode status = requested status */
        while ( (creg = READ_ARC_REG(AR_IO_CREG_SLV0_OBSR) & 0x8) == 0);
        /* Protect AR_IO_CREG_MST0_CTRL using lock and unlock of interruptions */
        saved = interrupt_lock();
        creg = READ_ARC_REG(AR_IO_CREG_MST0_CTRL);
        creg &= ~(ADC_MODE_MASK);
        /* request ADC to go to Normal mode w/o calibration */
        creg |= ADC_NORMAL_WO_CALIB | ADC_CLOCK_GATE;
        WRITE_ARC_REG(creg, AR_IO_CREG_MST0_CTRL);
        interrupt_unlock(saved);
        /* Poll CREG Slave 0 for Power Mode status = requested status */
        while ( ((creg = READ_ARC_REG(AR_IO_CREG_SLV0_OBSR)) & 0x8) == 0);
    }

    WRITE_ARC_REG(ADC_CLK_ENABLE | ADC_INT_DSB, ADC_CTRL);
    WRITE_ARC_REG(ADC_CONFIG_SETUP, ADC_SET);
    WRITE_ARC_REG(ADC_CLOCK_RATIO & ADC_CLK_RATIO_MASK, ADC_DIVSEQSTAT);


    Serial.print("ADC_CTRL after write: ");
    Serial.print(ADC_CTRL, BIN);
    Serial.println();

    creg = READ_ARC_REG(ADC_CTRL);
    Serial.print("ADC_CTRL in CREG after write: ");
    Serial.print(ADC_CTRL, BIN);
    Serial.println();
}

void disableADC(){

  creg = READ_ARC_REG(ADC_CTRL);

  Serial.print("ADC_CTRL reg before disabling ADC ");
  Serial.print(creg, BIN);
  Serial.println();

  saved = interrupt_lock();

  creg &= ~(1 << 2);

  creg |= READ_ARC_REG(ADC_CTRL);

  WRITE_ARC_REG(creg, ADC_CTRL);

  interrupt_unlock(saved);

  creg = READ_ARC_REG(ADC_CTRL);

  Serial.print("ADC_CTRL reg after disabling ADC ");
  Serial.print(creg, BIN);
  Serial.println();
}

void setup() {

  Serial.begin(115200);
  while(!Serial);

  adc_normal_wo_calib_REFERENCE();

  creg = READ_ARC_REG(ADC_CTRL);

  Serial.print("In SETUP ADC_CTRL after norm wo calib ");
  Serial.print(creg, BIN);
  Serial.println();

  disableADC();

   creg = READ_ARC_REG(ADC_CTRL);

  Serial.print("In SETUP ADC_CTRL after disableADC() ");
  Serial.print(creg, BIN);
  Serial.println();
}

void loop() {
  // put your main code here, to run repeatedly:
}

I don't think my logic in disableADC() is correct yet, but I'm really looking at the difference in the register going from the adc_normal_wo_calib_REFERENCE() function back to setup()

Thanks in advance!

from arduinocore-arc32.

eriknyquist avatar eriknyquist commented on August 15, 2024

ADC_CTRL is a #define for the memory address of the ADC_CTRL register.

#define ADC_CTRL                   (0x80015003)

So when you do this;

Serial.print(ADC_CTRL, BIN);

You're not actually printing out the value stored at that address, you're printing the address itself. It's the same as doing this:

Serial.print(0x80015003, BIN);

from arduinocore-arc32.

claudiaAl avatar claudiaAl commented on August 15, 2024

Arg dumb mistake! Thank you sir :-)

from arduinocore-arc32.

eriknyquist avatar eriknyquist commented on August 15, 2024

No problem.

from arduinocore-arc32.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.