if the AdcRng function is called with the parameter iCode=0, the iCode can never be set to 1 because the mask is probably wrong i1 = pPort->CON & 0xfffcfff;
uint32_t AdcRng(ADI_ADC_TypeDef *pPort, uint32_t iRef, uint32_t iGain, uint32_t iCode)
{
uint32_t i1 = 0;
i1 = pPort->MDE & 0xff07;
pPort->MDE = i1 | ((iGain & 0xf8));
i1 = pPort->CON & 0xfffcfff;
if(iCode) {
i1 |= 1 << 18;
}
pPort->CON = i1 | ((iRef & 0x3000));
return 1;
}
- ADCxCON.18
- 0 or ADCCON_ADCCODE_INT for bipolar (C type int) result.
- 1 or ADCCON_ADCCODE_UINT to truncate negative values to 0.
bit 18 already remains at 0 regardless of the iCode parameter
Rastislav Kotesovsky