这几天学了ADC和DMA,想结合使用一下。但是今天写代码出现了问题。ADC没法把值通过DMA给一个数组。但是可以直接读取ADC的值,说明ADC程序是可以的。贴出代码吧。
#include "DMA.h"
#include "stm32f10x.h"
u16 size;
void MYDMA_Init1(uint32_t MADDR,uint32_t ADC_ADDR,u16 BSIZE)
{
DMA_InitTypeDef DMA_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
size=BSIZE;
DMA_InitStruct.DMA_BufferSize=BSIZE;
DMA_InitStruct.DMA_DIR=DMA_DIR_PeripheralSRC; //íaéèμ½Äú′æ
DMA_InitStruct.DMA_M2M=DMA_M2M_Disable;
DMA_InitStruct.DMA_MemoryBaseAddr=MADDR;
DMA_InitStruct.DMA_MemoryDataSize=DMA_MemoryDataSize_HalfWord;
DMA_InitStruct.DMA_MemoryInc=DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_Mode=DMA_Mode_Circular;
DMA_InitStruct.DMA_PeripheralBaseAddr=ADC_ADDR;
DMA_InitStruct.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord;
DMA_InitStruct.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_Priority=DMA_Priority_High;
DMA_Init(DMA1_Channel1,&DMA_InitStruct);
}
void MYDMA_Init2(uint32_t MADDR,uint32_t USART_ADDR,u16 BSIZE)
{
DMA_InitTypeDef DMA_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
size=BSIZE;
DMA_InitStruct.DMA_BufferSize=BSIZE;
DMA_InitStruct.DMA_DIR=DMA_DIR_PeripheralDST; //Äú′æμ½íaéè
DMA_InitStruct.DMA_M2M=DMA_M2M_Disable;
DMA_InitStruct.DMA_MemoryBaseAddr=MADDR;
DMA_InitStruct.DMA_MemoryDataSize=DMA_MemoryDataSize_HalfWord;
DMA_InitStruct.DMA_MemoryInc=DMA_MemoryInc_Disable;
DMA_InitStruct.DMA_Mode=DMA_Mode_Normal;
DMA_InitStruct.DMA_PeripheralBaseAddr=USART_ADDR;
DMA_InitStruct.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord;
DMA_InitStruct.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_Priority=DMA_Priority_Medium;
DMA_Init(DMA1_Channel4,&DMA_InitStruct);
}
void A2M_DMA_Enable()
{
DMA_Cmd(DMA1_Channel1,DISABLE);
DMA_SetCurrDataCounter(DMA1_Channel1,size);
DMA_Cmd(DMA1_Channel1,ENABLE);
ADC_DMACmd(ADC1,ENABLE);
/*while(DMA_GetFlagStatus(DMA1_FLAG_TC1)==RESET);
DMA_ClearFlag(DMA1_FLAG_TC1);*/
}
void M2U_DMA_Enable()
{
DMA_Cmd(DMA1_Channel4,DISABLE);
DMA_SetCurrDataCounter(DMA1_Channel4,size);
DMA_Cmd(DMA1_Channel4,ENABLE);
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);
while(DMA_GetFlagStatus(DMA1_FLAG_TC4)==RESET);
DMA_ClearFlag(DMA1_FLAG_TC1);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
怎么发文件?
一周热门 更多>