|
#include "main.h"
u8 DmaBuffere[2][RHEOSTAT_NOFCHANEL]={0};
extern u8 flag[2],Bufbj;
void My_DMA_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
/* Enable ADC3, DMA and GPIO clocks ****************************************/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel= DMA2_Stream0_IRQn;//TIM2_IRQn; //
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* DMA2 Stream0 channel2 configuration **************************************/
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)RHEOSTAT_ADC1_DR_ADDR;
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)DmaBuffere[0];//数组名表示首地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = RHEOSTAT_NOFCHANEL*2;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
DMA_ClearITPendingBit(DMA2_Stream0,DMA_IT_TCIF0);//DMA_IT_HTIF0
DMA_ClearITPendingBit(DMA2_Stream0,DMA_IT_HTIF0);
DMA_ITConfig(DMA2_Stream0,DMA_IT_TC, ENABLE);
DMA_ITConfig(DMA2_Stream0, DMA_IT_HT, ENABLE);
DMA_Cmd(DMA2_Stream0, ENABLE);
}
//DMA_PeripheralDataSize_HalfWord++DMA_PeripheralDataSize_Byte
void DMA2_Stream0_IRQHandler(void) // 使用DMA中断采集数据,不会容易丢失数据
{
if (DMA2->LISR&0x20)
{
DMA2->LIFCR|=0x20;
flag[0]=1;
}
if (DMA2->HISR&0x10)
{
DMA2->HIFCR|=0x10;
flag[1]=1;
}
}
哪里不对了,半进不了,
|
|