本帖最后由 yuliang33 于 2012-11-6 09:58 编辑
贴程序
#define ADC1_DR_Address ((u32)0x4001244C)
vu16 ADC_ConvertedValue[1000];
void DMA_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;//定义DMA初始化结构体
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);//使能DMA时钟
DMA_DeInit(DMA1_Channel1);//复位DMA通道1
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //定义 DMA通道外设基地址=ADC1_DR_Address
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue; //定义DMA通道存储器地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//指定外设为源地址
DMA_InitStructure.DMA_BufferSize = 1;//定义DMA缓冲区大小1
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//当前外设寄存器地址不变
DMA_InitStructure.DMA_MemoryInc = DMA_PeripheralInc_Enable;//当前存储器地址递增
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//定义外设数据宽度16位
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //定义存储器数据宽度16位
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA通道操作模式位环形缓冲模式
DMA_InitStructure.DMA_Priority = DMA_Priority_High;//DMA通道优先级高
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//禁止DMA通道存储器到存储器传输
DMA_Init(DMA1_Channel1, &DMA_InitStructure);//初始化DMA通道1
DMA_ITConfig(DMA1_Channel1,DMA_IT_TC,ENABLE); //开传输完成中断
DMA_Cmd(DMA1_Channel1, ENABLE); //使能DMA通道1
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void DMA1_Channel1_IRQHandler(void)
{
u16 i;
u16 k[1000];
if(DMA_GetITStatus(DMA1_IT_TC1) != RESET) //数据传输完成
{
DMA_ClearITPendingBit(DMA1_IT_TC1);
for(i=0;i<2;i++)
{
k = (u32)ADC_ConvertedValue*3300/4096;
send_UART1_one(k>>8);
send_UART1_one(k);
}
}
}
硬件:ADC1通道12接至3.3V
程序功能:ADC1采集,使用DMA将数据放入内存,然后DMA传输完成中断,将数据发送至串口;
问题:DMA_BufferSize = 1;串口接收“0C E3 ”循环;数据正常;
DMA_BufferSize = 2;串口接收“0C E3 00 00 00 00”循环;数据异常;
DMA_BufferSize >= 3;串口接收“00 00 00 00 00 00”循环;数据异常
(中断中i值相应变动为i < DMA_BufferSize);
新手 找不到问题 |