Giter VIP home page Giter VIP logo

Comments (8)

Mirageofmage avatar Mirageofmage commented on June 9, 2024

_status.dr is updated through a union based on the result of a function call. See the source which defines the structure below, specifically line 113.

typedef union {
struct {
struct __attribute__((__packed__)) {
bool por : 1; //!< status: power on reset
bool crccfg: 1; //!< status: crc
bool dr : 1; //!< status: data ready
};
uint8_t : 1; //!< !addr[0]
uint8_t addr : 2; //!< addresse
uint8_t : 2; //!< EMTPY
};
uint8_t raw;
} status_t;
status_t _status;

IRQ_handler calls the read function, which calls the transfer function, which in turn sets the value of _status.dr based on the result of the SPI transfer

MCP3x6x::status_t MCP3x6x::_transfer(uint8_t *data, uint8_t addr, size_t size) {
_spi->beginTransaction(SPISettings(MCP3x6x_SPI_SPEED, MCP3x6x_SPI_ORDER, MCP3x6x_SPI_MODE));
noInterrupts();
digitalWrite(_pinCS, LOW);
_status.raw = _spi->transfer(addr);
_spi->transfer(data, size);
digitalWrite(_pinCS, HIGH);
interrupts();
_spi->endTransaction();
return _status;
}

Is _status.dr not updating? If it isn't try using the develop branch since commits to that branch may solve your issue.

from arduino_mcp3x6x_library.

AhdHahn avatar AhdHahn commented on June 9, 2024

Hello Mirageofmage,
Thank you very much for fast reply.
In the "_transfer" function sets the "_status.raw" value
which part of the "_transfer" function changes the “_status.dr” logic?
Thanks.

from arduino_mcp3x6x_library.

nerdyscout avatar nerdyscout commented on June 9, 2024

_status.dr is just one bit within _status. as all mcp3x6x do full duplex, and the first byte read back corresponds to the status, the return value of spi->transfer(addr) corresponds exactly bit aligned to this status, just like Mirageofmage pointed out with the status_t union

from arduino_mcp3x6x_library.

nerdyscout avatar nerdyscout commented on June 9, 2024

@arthanth is this some real issue or are you just trying to understand the code? if first please specify your problem.

from arduino_mcp3x6x_library.

AhdHahn avatar AhdHahn commented on June 9, 2024

I use MCP3564 (ADC 9 Click) with ESP32 (Wemos D1 R32 pinOut-R32). Voltage incorect value it show 0 and 2.39 in mux mode. I try to fix follow the previous issue but it does not work now. So I am trying to understand the code and debuging.

from arduino_mcp3x6x_library.

FelixWT avatar FelixWT commented on June 9, 2024

Voltage incorect value it show 0 and 2.39 in mux mod

You should check the configuration 0 register of your MPC3564. The default Voltage Reference is set to 2.4V.

image

And also check ADCDATA REGISTER if the result is what you expected.

from arduino_mcp3x6x_library.

nerdyscout avatar nerdyscout commented on June 9, 2024

a few more thoughts:

  • check if you got a version mcp3x6xr or without r, the once without r do not have VREF_SEL. did you connect anything to VREF+-?
  • it helps a lot to have a logic analyzer / oscilloscope running in parallel to your SPI
    • I just checked if the code builds for ESP32, but never actually connected one. you might need to change _spi->begin(); adding the actual pins. Also just yesterday figured out there is a _spi->transfer32(); for at least some ESP32 variants... should not matter to you, but might help to speed up communication.
  • mcp.begin() does set some defaults, which are not necessarily the defaults according the datasheet. all settings done by you (select channel, clk_sek, vref, gain, timing, ...) should be done after the begin()

from arduino_mcp3x6x_library.

nerdyscout avatar nerdyscout commented on June 9, 2024

I am closing this as no actual question/issue seems open. please feel free to come back if you run into troubles again.

from arduino_mcp3x6x_library.

Related Issues (11)

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.