请问各位大人们,stm32f4系列怎么用dma和ad做到多路采集?现在参考网上的程序做到了单路的采集,要如何修改呢?求各位大神们指点,小白我感激不尽。
void ADC3_IN11_Config(void)
{
/***GPIO设置***/
RCC->AHB1ENR |= (1<<2); //打开GPIOC时钟
GPIOC->MODER &= 0xfffffff3;//PC1模拟模式
GPIOC->MODER |= 0x0000000C;
GPIOC->PUPDR &= 0xfffffff3;//无上拉无下拉
/***DMA设置***/
RCC->AHB1ENR |= (1<<22); //使能DMA2时钟
ADC3->CR2 &= ~(1<<8);//ADC3 dma发送模式除能
DMA2_Stream0->CR &= 0xFFFFFFFE; //除能DMA2_Stream0
while(DMA2_Stream0->CR & 0x00000001);//确保DMA可以被设置
DMA2->LIFCR |= 0x0000003D;//传送前清空DMA1_Stream5所有中断标志
DMA2_Stream0->PAR = (uint32_t)&ADC3->DR;//设置外设地址
DMA2_Stream0->M0AR = (uint32_t)ADC3ConvertedVault; //设置内存地址
DMA2_Stream0->CR |= 0x0002800;//16位数据
DMA2_Stream0->NDTR = 10000; //设置dma传输数据的数量
/*
设置dma2通道2,即ADC3
优先级Medium
传输方向外设到内存
内存递增模式
循环模式
传输完成中断
*/
DMA2_Stream0->CR |= ( 0x04000000 | 0x00010000 | 0x0
| (1<<10) | (1<<8) | (1<<4) );
NVIC->IP[56] = 0xB0;
NVIC->ISER[1] |= (1<<(56-32));
DMA2_Stream0->CR |= 1; //DMA2数据流0使能
/***ADC3设置***/
RCC->APB2ENR |= (1<<10); //使能ADC3时钟
ADC3->SQR1 = 0x00000000;//转换一个通道
ADC3->SQR3 = 0x0000000B;//第一个通道为ADC3_in11
ADC3->CR1 &= 0x00000000;
ADC3->CR2 &= 0x00000000;
ADC3->CR2 |= (1<<1); //连续转换
ADC3->CR2 |= (1<<9); //最后一次ADC转换后发出dma请求
ADC3->CR2 |= (1<<0); //开启AD转换
ADC3->CR2 |= (1<<8);//ADC dma发送模式使能
ADC3->CR2 |= (1<<30); //规则通道转换开始
}
void DMA2_Stream0_IRQHandler (void)
{
uint32_t i;
uint32_t Average = 0;
if(DMA2->LISR & 0x00000010)
{
DMA2->LIFCR |= 0x00000010;
for(i = 0; i < 10000; i++) // 对一万个数据取平均值
Average += ADC3ConvertedVault[i];
Average *= 3.3;
Average /= 40950;
TXbuffer[0] = ( Average / 1000 ) % 10 + 0x30;//转换成ASCII码
TXbuffer[2] = ( Average / 100 ) % 10 + 0x30;
TXbuffer[3] = ( Average / 10 ) % 10 + 0x30;
TXbuffer[4] = Average % 10 + 0x30;
LCD_DispStr(100, 100, TXbuffer, &tFont);
}
}
|