Comments (7)
Hey Felix,
I've run into this exact issue (also with the ESP32S3). I'm currently working on a PR to make this library fully compatible ( GH-5), but for the time being here's the fix in order to get analogRead to work.
In MCP3x6x.h
typedef union {
struct {
struct __attribute__((__packed__)) {
bool por; //!< status: power on reset
bool crccfg; //!< status: crc
bool dr; //!< 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;
Must get updated to
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;
There's an issue on the ESP32S3 specifically where the bit assignment in the union doesn't work properly unless explicitly stated.
You can also optionally add _status = read(&adcdata);
after the
while (!_status.dr) {
_status = read(&adcdata);
}
in analogRead; however, I'm not sure if this is necessary or not.
Best,
from arduino_mcp3x6x_library.
could you please specify what you mean by:
Also dude to the layout error in swap the pin definition of MISO & MOSI in the class Constructor .
where did I swap something?
from arduino_mcp3x6x_library.
could you please specify what you mean by:
Also dude to the layout error in swap the pin definition of MISO & MOSI in the class Constructor .
where did I swap something?
This is the problem on my end. It is dude to the wrong PCB layout of my project.
thank you for your reply
from arduino_mcp3x6x_library.
Mirageofmage
Thank you for your quick reply , I've tried what you suggest and it works now!
But the readings keeps on increasing even when I do nothing to the device.
By the way, I should have mentioned this in my post that I'm using MCP3562R: dual channel variant.
I'm trying to read ADC readings from Device 1. So I'm assuming I should change MCP_CH0
definition in MCP3x6x.h
from 0x08
to 0x01
from arduino_mcp3x6x_library.
I manage to make it work now.
What I did was twick the configuration a bit setDataFormat(data_format::SGN_DATA);
And change the reference voltage to 3.3
. Also as I mentioned in my last post I change MCP_CH0
definition in MCP3x6x.h
from 0x08
to 0x01
.
And now I'm getting the readings almost 6.6 which is what it should be while off load.
Apart from the topic, shouldn't the code here
be like this?
_spi->begin(_pinCLK,_pinMISO,_pinMOSI,_pinCS);
otherwise the pin configurations will be overwrite by default SPI configurations.
from arduino_mcp3x6x_library.
There is no begin()
in SPIClass which takes any parameters, therefore no :)
Please check the examples, there I use a setup with a custom SPI, this should also help with your pin swap without modifiying my lib.
SPIClass mySPI(&sercom1, 12, 13, 11, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_3);
MCP3561 mcp(8, 7, 10, &mySPI, 11, 12, 13);
...
_spi = theSPI;
...
_spi->begin();
As you can see the custom SPI mySPI
is passed through the constructor into the privat member _spi
which therefore got the correct pin definitions.
As far as I understand your schematic your try to do some differential reading as well as a single ended reading. There should be nothing wrong with this, but my personal approach would be to handle both the same way... anyway, you should not need to change the definition of MCP_CH0
but instead mcp.enableScanChannel(MCP_DIFFA);
for enabling reading differntial signals and mcp.enableScanChannel(MCP_CH2)
for reading pressure - altleast in ScanMode.
In MuxMode just do int32_t adcdata = mcp.analogRead(MCP_DIFFA);
or MCP_CH2 whenever you like.
from arduino_mcp3x6x_library.
There is no
begin()
in SPIClass which takes any parameters, therefore no :)
Well , it seem that Arduino core didn't provide it but in ESP32 core it does. Check out the following link for SPI library in esp32 core
(http://github.com/espressif/arduino-esp32/blob/9275dbff942bb2ccce62632607500ad27dd0513a/libraries/SPI/src/SPI.h#L63)
And yes I did try out your code as well. But again it seems to be Arduino and ESP32 core difference I can't get your configurations to work.
int32_t adcdata = mcp.analogRead(MCP_DIFFA);
Ah, you did provide the settings I want. This is great it feels weird to modifiy your library.
Thanks for this amazing library!
from arduino_mcp3x6x_library.
Related Issues (10)
- Problems with SDO on MCP3464 HOT 3
- Some questions about the SPI HOT 4
- Strange issue with MCP3561 HOT 3
- How do I add license in my source code ? HOT 2
- ESP32-S3-Mini and MCP3462R not working in Mux Mode HOT 24
- Not really an issue :) HOT 3
- Function: _getValue(uint32_t raw) wrong return HOT 8
- How is the “_status.dr” logic changed? HOT 8
- Difficulty with compiling for RP2040 using earlephilhower core HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino_mcp3x6x_library.