微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI Zigbee设计交流 > CC2530 序列采样ADCCON2寄存器问题

CC2530 序列采样ADCCON2寄存器问题

时间:10-02 整理:3721RD 点击:

配置ADC序列采样不工作,使用IAR  watch检查各寄存器设置,发现ADCCON2寄存器有问题,复位时ADCCON2值为00x16,我清零下ADCCON2 &=0x00,ADCCON2值变为0x06,再设置ADCCON2 |= 0x87,ADCCON2值为0x86,运行几次后寄存器值还会变化。为什么这个寄存器是这样?关键是我用裸机测试程序ADC_DMA时,ADCCON2也是这样,但是裸机程序是可以成功的,在协议栈中就不行,一直停在 while( !(DMAIRQ & HAL_DMA_CHANNEL_0)) ,就是DMAIRQ貌似一直为0。求解答,附配置程序。

//DMA配置
void dma_channel_init (DMA_DESC __xdata *dma_p,uint8 __xdata *dest_adr,uint8 lenl,uint8 trig)
{

  // Setup DMA confiuration
  dma_p->SRCADDRH  = (uint8)((uint16)(&X_ADCH) >> 8);
  dma_p->SRCADDRL  = (uint8)((uint16)(&X_ADCH));
  dma_p->DESTADDRH = (uint8)((uint16)(dest_adr) >> 8);
  dma_p->DESTADDRL = (uint8)((uint16)(dest_adr));
  dma_p->VLEN      = HAL_DMA_VLEN_FIXED;
  dma_p->LENH      = 0;
  dma_p->LENL      = lenl;                   // Tranfer Count
  dma_p->WORDSIZE  = HAL_DMA_WORDSIZE_BYTE;
  dma_p->TMODE     = HAL_DMA_TMODE_SINGLE;
  dma_p->TRIG      = trig;     // Channel trigger
  dma_p->SRCINC    = HAL_DMA_SRCINC_0;
  dma_p->DESTINC   = HAL_DMA_DSTINC_1;
  dma_p->IRQMASK   = HAL_DMA_IRQMASK_DISABLE;
  dma_p->M8        = HAL_DMA_M8_USE_8_BITS;
  dma_p->PRIORITY  = HAL_DMA_PRI_HIGH;
  
    //配置DMA 0
  DMA0CFGL =((uint16)dma_p);
  DMA0CFGH =((uint16)dma_p >> 8);
 
}
/*****************************************************************
函数名称:
功能介绍:ADC_DMA初始化
参数描述:无
返回值:无
*/
void intsystem(void)
{
  P0SEL |= adChannel;
  P0DIR &= ~adChannel;
  ADCCFG |= adChannel;
  // Configure DMA channel 0
  dma_channel_init(dma_channel, adc_data, adChannelNum, HAL_DMA_TRIG_ADC_CHALL);
  
  //ad序列化采样配置
  ADCCON2 =0x00;
  
  ADCCON2 =(HAL_ADC_REF_AVDD|HAL_ADC_RESOLUTION_8|HAL_ADC_CHN_AIN7);//0x87

  //选择 触发源
  ADCCON1 = ADCCON1_STSEL;

}
/*****************************************************************
函数名称:
功能介绍:启动AD序列转换
参数描述:无
返回值:无
*/
void halADSeqStart(void)
{ 

  //启动MDA0通道
  DMAARM |= (HAL_DMA_CHANNEL_0);
  asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");
  ADCCON1 |= ADCCON1_ST;
  //等待采样完成
  while( !(DMAIRQ & HAL_DMA_CHANNEL_0)); 
   //clear interrupt flag
  DMAIRQ &= ~HAL_DMA_CHANNEL_0;
  
  for(i=0 ; i< 4 ; i++)
   {
      if(adc_data[i] & 0x80) adc_data[i] = 0;
      temp[i]= adc_data[i];
   }
          
          
   if ( AF_DataRequest( &SampleApp_Periodic_DstAddr, &SampleApp_epDesc,
	                SAMPLEAPP_ADC_CLUSTERID,//自己定义一个
	                5,                  // 数据长度         
                        temp,                     //数据内容
	                &SampleApp_TransID, 
	                AF_DISCV_ROUTE,
	                AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
	                { 
                          HalLedSet (HAL_LED_2, HAL_LED_MODE_TOGGLE);
	                }
    else
      {
      // Error occurred in request to send.
       }
     
     Onboard_wait(2000);
}



协议栈里面有定义DMA和ADC的驱动函数,直接调用会有问题吗?

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top