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.

CC2530测量内部电压VDD/3

Other Parts Discussed in Thread: CC2530, Z-STACK

使用Z-Stack,CC2530多EndDevice和一个Coordinator组网,组网成功。仿照Z-Stack中hal_adc.c文件下面的bool HalAdcCheckVdd (uint8 limit)函数,改了一个uint16 HalAdcGetVdd(void)函数,区别如下。

原来的函数bool HalAdcCheckVdd (uint8 limit)判断供电电压是否在某个门限;

新改的函数uint16 HalAdcGetVdd(void)输出供电电压的测量值。

代码如下。

uint16 HalAdcGetVdd(void)
{
  uint16 value;
  uint8 tmpADCCON3 = ADCCON3;  // Save ADCCON3 to restore later

  /* Clear ADC interrupt flag */
  ADCIF = 0;
  
  /* Setup the new value for conversion 
     Internal reference 1.15V for CC2530, 7 bits ENOB, VDD/3
  */
  ADCCON3 = (HAL_ADC_REF_125V | HAL_ADC_DEC_064 | HAL_ADC_CHN_VDD3);

  /* Wait for the conversion to finish */
  while ( !ADCIF );

  /* Get the result */
  value = ADCL;
  value |= ((uint16) ADCH) << 8;
  value >>= 2;

  // Restore ADCCON3
  ADCCON3 = tmpADCCON3;
  
  return value;
}

几乎都是抄原来的函数,因为是8位测量,最终期望value测到的值是VDD/3/1.15*256。也有可能是VDD/3/1.15*128。

烧写到CC2530,VDD供电电压3.3V,串口输出value的低8位,发现value值0x68,0x4A,0x8F这样的范围波动,与期望不符。请问从何入手调试?

PS: 如果不用Z-Stack,直接裸机写一个ADC测量VDD/3的程序,输出正常。