MrHause / ADS1115_Library

ADS1115 library for STM32 using HAL
10 stars 3 forks source link

void prepareConfigFrame issues #1

Closed Oerdna closed 3 months ago

Oerdna commented 2 years ago

Not correct function of serialization of configure type struct to byte array.

static void prepareConfigFrame(uint8_t *pOutFrame, ADS1115_Config_t config){
    pOutFrame[0] = 0x01;
    pOutFrame[1] |= (config.channel << 6) | (config.pgaConfig << 3)
                    | (config.operatingMode << 0);
    pOutFrame[2] |= (config.dataRate << 5) | (config.compareMode << 4) | (config.polarityMode << 3)
                    | (config.latchingMode << 2) | (config.queueComparator << 1);
}

Should be:

    pOutFrame[1] |= (config.channel << 4) | (config.pgaConfig << 1)
                    | (config.operatingMode << 0);
    pOutFrame[2] |= (config.dataRate << 5) | (config.compareMode << 4) | (config.polarityMode << 3)
                    | (config.latchingMode << 2) | (config.queueComparator << 0);
tusker-tools commented 1 year ago

I just spent an hour with debugging, then I remembered this PR and yes, it was exactly what caused my problem! Thanks @Oerdna, this was very useful! You saved me another hours of debugging!

I created a pull request for it, please @MrHause merge it ASAP in order to prevent other people facing the same problems.

Nevertheless thanks to @MrHause for this nice and cleanly coded library. It was the best one for STM32 I could find in GitHub!

JohnDSN commented 8 months ago

I read it late. I also had to tinker with this error!

zhangyy103 commented 3 months ago

两位技术大佬您好,能否看一下我的问题,感谢您对我的帮助 | Hello, technical experts. Could you please take a look at my question? Thank you for your help.

MrHause commented 3 months ago

Thank you for finding bug. Pull request has been merged into master branch.

MrHause commented 3 months ago

Fixed