nerdyscout / Arduino_MCP3x6x_Library

Library to support Microchip MPC3x6x 16/24bit analog to digital converters.
https://nerdyscout.github.io/Arduino_MCP3x6x_Library
MIT License
18 stars 9 forks source link

How is the “_status.dr” logic changed? #8

Closed AhdHahn closed 1 year ago

AhdHahn commented 1 year ago

How is the “_status.dr” logic changed? (In the IRQ_handler() does not change the “_status.dr”) Thanks

Mirageofmage commented 1 year ago

_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.

https://github.com/nerdyscout/Arduino_MCP3x6x_Library/blob/c9de707794ecda62178ce5cdd86d50e9d86584eb/MCP3x6x.h#L108-L121

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

https://github.com/nerdyscout/Arduino_MCP3x6x_Library/blob/6cce10135956cceaa817b629f27d1a70c646e8a2/lib/MCP3x6x/MCP3x6x.cpp#L80-L90

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

AhdHahn commented 1 year ago

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.

nerdyscout commented 1 year ago

_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

nerdyscout commented 1 year ago

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

AhdHahn commented 1 year ago

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.

FelixWT commented 1 year ago

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.

nerdyscout commented 1 year ago

a few more thoughts:

nerdyscout commented 1 year ago

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