Giter VIP home page Giter VIP logo

Comments (24)

LeKrakenTheCode avatar LeKrakenTheCode commented on June 9, 2024

What's the speed of your SPI bus? I remember having some issues if the speed was over 500k. I'm currently running w/ 200k\

I was running at 10MHz. I lowered to 200KHz and still no change.

from arduino_mcp3x6x_library.

Mirageofmage avatar Mirageofmage commented on June 9, 2024

If you have access to a scope, can you check the activity on MISO?

from arduino_mcp3x6x_library.

LeKrakenTheCode avatar LeKrakenTheCode commented on June 9, 2024

Sorry for the delay. Was feeling rather unwell this weekend. Working on it now.

from arduino_mcp3x6x_library.

LeKrakenTheCode avatar LeKrakenTheCode commented on June 9, 2024

If you have access to a scope, can you check the activity on MISO?

image
image

I have this tool that can view SPI. Does this help? Please ignore the CS line, it is not connected as i didn't break out a header for that pin, however the analyzer is set to ignore the CS line for now.

from arduino_mcp3x6x_library.

nerdyscout avatar nerdyscout commented on June 9, 2024

MISO and MOSI seem to show reasonable signals. Seems like the second picture is showing a 1Byte command followed by another 2Byte command... I did not try to figure out which are these. But it seems save to say MCP3x6x::read(Adcdata *data) is never executed as this would result in a 3-5Byte command. At least this is not shown in any of these pictures.

I still suspect the issue in this little snippet:

    settings.mux = ch;
    _status      = write(settings.mux);
    _status      = conversion();
    while (!_status.dr) {
      _status = read(&adcdata);
    }

please put an Serial.print(_status.dr) inside the loop and right in front of it, it looks like this is currently not executed. This bit should be set when conversion started and reset when valid data available. As this bit is part of the status byte endianness is important, but also timing of spi speed vs conversion speed might cause it.

from arduino_mcp3x6x_library.

LeKrakenTheCode avatar LeKrakenTheCode commented on June 9, 2024

image
Here's the change and here is the output:
image
only one appears to be running.

from arduino_mcp3x6x_library.

Mirageofmage avatar Mirageofmage commented on June 9, 2024

image Here's the change and here is the output: image only one appears to be running.

I've had issues with the while loop, in my implementation I just directly read instead of waiting for the data ready bit. I have to be careful with my sample rate or it returns the same value for each of the channels.

from arduino_mcp3x6x_library.

LeKrakenTheCode avatar LeKrakenTheCode commented on June 9, 2024

image

No change to the output.

from arduino_mcp3x6x_library.

Mirageofmage avatar Mirageofmage commented on June 9, 2024
image

from arduino_mcp3x6x_library.

LeKrakenTheCode avatar LeKrakenTheCode commented on June 9, 2024

still no change to the output:

image

Trying to read MCP_TEMP.

from arduino_mcp3x6x_library.

Mirageofmage avatar Mirageofmage commented on June 9, 2024

@nerdyscout
image

Question on why the int32 is truncated to 25 bits in adcdata? The ADC can return either left aligned or right aligned 32 bit values. The assignment in the result struct retains all 32 bits

from arduino_mcp3x6x_library.

nerdyscout avatar nerdyscout commented on June 9, 2024

Question on why the int32 is truncated to 25 bits in adcdata? The ADC can return either left aligned or right aligned 32 bit values. The assignment in the result struct retains all 32 bits

yes, the dataformat is choosen within the begin() funtion

from arduino_mcp3x6x_library.

Mirageofmage avatar Mirageofmage commented on June 9, 2024

Question on why the int32 is truncated to 25 bits in adcdata? The ADC can return either left aligned or right aligned 32 bit values. The assignment in the result struct retains all 32 bits

yes, the dataformat is choosen within the begin() funtion

I see that, but my point is that if somebody chooses a left aligned output, then the 7 leftmost bits get masked out? Or am I understanding it wrong?

from arduino_mcp3x6x_library.

nerdyscout avatar nerdyscout commented on June 9, 2024

I assume you are right.
My intention was to make this library for getting easy started as the component is really complex. This is why the begin functions sets a few default parameters... they might be not good for every case, but if someone chooses to set up their own config than I would suspect it is on him self to handle this. This is also why I refactored settings to be a class by its own so in future it could be a parameter of begin().

from arduino_mcp3x6x_library.

LeKrakenTheCode avatar LeKrakenTheCode commented on June 9, 2024

Any other idea's I can try?

from arduino_mcp3x6x_library.

Mirageofmage avatar Mirageofmage commented on June 9, 2024

Any other idea's I can try?

Maybe try returning adcdata.value directly at the end of analogRead?

So
return adcdata.value;
instead of
return result.raw[(...

Otherwise I don't really have a clue/it has to be in hardware? I've been testing the same code revisions on my hardware and it's been working (though I'm not using the R revision).

I remember that you put the pins in the constructor of whichever MCP3x6x class you used, I instead opted to redefine the consts in the default constructor.

So my object declaration is just
MCP3561 mcp;

with #defines for MOSI, MISO, SS, SCK, and IRQ (if required). The default SPI interface through Arduino is selected.

from arduino_mcp3x6x_library.

Mirageofmage avatar Mirageofmage commented on June 9, 2024

I actually think you HAVE to use #define to select pins instead of using the constructor, it doesn't look like parameters are properly passed through the constructor to the SPI object

The parameters required are

#define MOSI 
#define MISO
#define SS
#define SCK

from arduino_mcp3x6x_library.

nerdyscout avatar nerdyscout commented on June 9, 2024

I actually think you HAVE to use #define to select pins instead of using the constructor, it doesn't look like parameters are properly passed through the constructor to the SPI object

The parameters required are

#define MOSI 
#define MISO
#define SS
#define SCK

as his logic analyzer pictures have proven some SPI communication I don't see why this should be the case.

from arduino_mcp3x6x_library.

Mirageofmage avatar Mirageofmage commented on June 9, 2024

from arduino_mcp3x6x_library.

nerdyscout avatar nerdyscout commented on June 9, 2024

@LeKrakenTheCode please publish your code. either setup a new repository as minimal example which reproduces your issue or the original code.

from arduino_mcp3x6x_library.

LeKrakenTheCode avatar LeKrakenTheCode commented on June 9, 2024

from arduino_mcp3x6x_library.

LeKrakenTheCode avatar LeKrakenTheCode commented on June 9, 2024

from arduino_mcp3x6x_library.

nerdyscout avatar nerdyscout commented on June 9, 2024

seems like it could be fixed by something like this, will work on a better fix later.

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);
#ifdef ARDUINO_ARCH_ESP32
  _spi->writeBytes(data, size);
#else
  _spi->transfer(data, size);
#endif
  digitalWrite(_pinCS, HIGH);
  interrupts();
  _spi->endTransaction();

  return _status;
}

from arduino_mcp3x6x_library.

McMillanFlowProducts avatar McMillanFlowProducts commented on June 9, 2024

Just changed the _transfer function, still getting a reply of zero. I am LeKrakenTheCode, I just ended up creating the issue under the wrong account and never changed it.

*** I have removed a println from the analogread function, i am now getting a constant value of 130 (raw adc value) regardless of what i am reading in the mux. i have updated code on github.
image

image

image

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.