Closed limingjie closed 2 years ago
The comment of the code is also the opposite of the document.
ADC reference clock frequency selection bit, if the bit is 0, select the slow clock, and 384 Fosc cycles are required for each ADC. If the bit is 1, select the fast clock, and 96 Fosc cycles are required for each ADC
* Input : uint8_t speed clock setting 1 Slow 384 Fosc 0 Fast 96 Fosc
Good catch- I'd write it like this to make it even more clear: ADC_CFG = (ADC_CFG & ~bADC_CLK) | speed;
If you send a pull request, we can merge it.
I am writing an email to tech@wch.cn for this issue. Also submit an issue here, in case anyone meets the same problem.
The
&=
operator is misused in theADCInit()
method in adc.c. The expression on the right side of the operator&=
will be calculated first, it may lead to an unexpected value in a certain case.The 3rd case failed to set the bit.
It should have been like this.
All cases work as expected.