This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Can't Read ADC Value on CC2541

Whenever I perform an ADC conversion, the result is exactly 0. I have tried to enable to correct pins as analog inputs and set the proper voltage reference. However, the result is always zero. Here is what I am doing:

APCFG = 0x40; // Signal is on P0.6 pin (AIN6)
HalAdcSetReference (HAL_ADC_REF_AIN7);

uint16 adcVal = HalAdcRead (HAL_ADC_CHANNEL_6, HAL_ADC_RESOLUTION_8);

Again, I adcVal is always exactly zero. I assume I must be missing a step. Is APCFG = 0x40 correct for P0.6?

  • Hi Jonathan,

    The only thing I can think of causing this is if P0DIR has this pin set as output which might drive the pin low or if the source impedance is very high. Have you measured the pin with a scope?

    Note that 8-bit resolution will shift the result down in HalAdcRead which can cause low-voltage signals to return 0.

    .:svend
  • To make sure I left no stone unturned, I tried the following with the same results (always zero):

    // Enable P0.6 as analog input:
    P0SEL = 0x00;
    P0DIR = 0x00;
    P0INP = 0xFF;
    APCFG = 0xC0;
    HalAdcSetReference (HAL_ADC_REF_AVDD);
    uint16 adcVal = HalAdcRead (HAL_ADC_CHANNEL_6, HAL_ADC_RESOLUTION_12);
    printf("adc: %d\n", adcVal);

  • So I am happy yet surprised to say that I found the problem. Even though HAL_ADC was set to TRUE in hal_board_cfg.h, for some reason, it was FALSE in hal_adc.c. I did a "Find in Files" for HAL_ADC, and I can't find any place where it is set to FALSE.

    So its a bit of a mystery, but placing a #define HAL_ADC TRUE in hal_adc.c fixed the problem.

    FYI, I am using the SensorTag example firmware.