fix the bug when those are some data in wire#3
fix the bug when those are some data in wire#3watershade wants to merge 3 commits intoJSC-electronics:mainfrom
Conversation
1. modify MCP342X_VERSION to version 1.0.5 to match your needs 2. splite teo convert funtion to different lines
1. flush obsolete data in Wire before read new data
|
|
||
| // Reset devices | ||
| MCP342x::generalCallReset(); | ||
| adc.generalCallReset(); |
There was a problem hiding this comment.
Why do you change this call from MCP342x::generalCallReset(). Is it necessary to fix your bug?
There was a problem hiding this comment.
Yes, it is necessary. It cannot be compiled (I used platformio not arduino ide) because it is not an static member function anymore.
In the original code, "Wire" is an static member, so you can define them to static member functions. But when you use an changeable "wire"(It is the functions we need), it become an normal functions. I think it is the reason why you remove "static" in 647b2ce. So I chose to change MCP342x to adc. Thanks.
| uint8_t buffer[len] = {}; | ||
|
|
||
| // To fix a bug to prevent there are some data haven't been read out. | ||
| #if 0 |
There was a problem hiding this comment.
I don't like the approach to fix a bug with two solutions which are affected by a build flag. Do you really need both? If not, I'd suggest to just flush the buffer.
There was a problem hiding this comment.
Yes, best to flush it. But in Arduino_mbed, flush haven't been implemented.:
void arduino::MbedI2C::flush() {
}It is the reason why I give another solution. The 2nd solution have a bug unintentionally,you can fix if to while like this:
// Solution2: Just to read out every useless data before get useful one
while(wire->available() > 0 ){
wire->read();
}
Because those many be some data inside it before read them out. (The data if generated when I try to test if there are any data inside of it). I can clear data out of just flush the old data before read new data. So I fix it.
But those examples to use them haven't been changed, I try to fix them.