F103 ADC DMA-GPIO_Mode_AIN

void init_adc1(void)

{

  ADC_InitTypeDef  ADC_InitStructure;

  GPIO_InitStructure.GPIO_Pin = /*GPIO_Pin_4|*/GPIO_Pin_5 ;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

 

//  RCC_ADCCLKConfig(RCC_PCLK2_Div2);

  ADC_DeInit(ADC1);

  ADC_InitStructure.ADC_ScanConvMode = ENABLE;

  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  ADC_InitStructure.ADC_NbrOfChannel = 2; //

  ADC_Init(ADC1, &ADC_InitStructure);

 

  adc_channel_config();

  ADC_DMACmd(ADC1,ENABLE);

  ADC_Cmd(ADC1, ENABLE);

  ADC_ResetCalibration(ADC1);

 

  while(ADC_GetResetCalibrationStatus(ADC1));

  ADC_StartCalibration(ADC1);

  while(ADC_GetCalibrationStatus(ADC1));

}

 

 

void ADC1_DMAConfig(void){

  DMA_InitTypeDef DMA_InitStructure;

  DMA_Cmd(DMA1_Channel1,DISABLE);

  DMA_DeInit ( DMA1_Channel1);

  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)0x4001244C; // ADC->DR Adresi

  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) ADC_ValArray; // hedef adresimiz

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // ADC kaynak. Veri y�n� ADC -> Haf?za

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; // ADC adresi sabit kalacak

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // Her de?er al?nd???na memory adresi 1 art?r?lacak

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;  // Kaynaktan al?nacak veri 16 bit

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; // Hedef b�y�kl�?� 16 bit

  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //veri al?nd?ktan sonra ba?a d�n�lecek.

  DMA_InitStructure.DMA_Priority = DMA_Priority_High ; // Kanal �nceli?i y�ksek. ( bu bize kalm??)

 

  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // haf?zadan haf?zaya transfer kapal?.

  DMA_InitStructure.DMA_BufferSize = 100; //

  DMA_Init(DMA1_Channel1, &DMA_InitStructure);

  DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);

  DMA_Cmd(DMA1_Channel1,ENABLE);

}

 

        if (GPIOB->IDR&GPIO_Pin_9) RAM[0]=0;else RAM[0]=1;

 

        if(RAM[0]&&!RAM[20])ADC_ExternalTrigConvCmd(ADC1, ENABLE);

 

        RAM[20]=RAM[0];

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值