1. 我原先是库函数方式没有操作系统实现内部AD+DMA转换,把他移植到ucos中初始化,如果只是用AD转换可以工作,如果用DMA方式就不工作,DMA配置移植到ucos中还需要修改吗,求大神指教,,
2. 我用的是stm32f4,怎么串口不配置他就可以工作,困扰了很多天了,郁闷,不配置就可以用串口调试工具或者终端来发送接收数据,为啥,,求解
[mw_shl_code=c,true]/*DMA·???????AD×???*/
u16 ad_dma[2]={0};
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStruct;
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);
ADC_DeInit();
DMA_DeInit(DMA2_Stream0);//????DMA2?????÷0
//DMA_InitStruct.DMA_PeripheralBaseAddr=ADC_DR_ADDR;
DMA_InitStruct.DMA_Channel = DMA_Channel_0;
DMA_InitStruct.DMA_PeripheralBaseAddr =0X4001204C;//?¨??DMA ?¨?????è?ù???· ADC1_BASE+0X04C; ADC->DR???·??ADC1-ADC2-ADC3??0X40012000-0X400123FF; ??????ADC1??0X000-0X04C; ADC2??0X100-0X14C; ADC3??0X200-0X24C
DMA_InitStruct.DMA_Memory0BaseAddr = (u32)&ad_dma;//??±ê?????????¨??DMA?¨???????÷???·
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStruct.DMA_BufferSize =2;
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//?±?°???è?????÷???·??±?
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;// ?±?°?????÷???·??±?
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//?¨?????è?????í????16??
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//?¨???????÷?????í??16??
DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;//DMA?¨????×÷???????·??????????
DMA_InitStruct.DMA_Priority = DMA_Priority_High;//????DMA?¨???????÷???????÷????
DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Disable;//DMA?¨??????????
DMA_InitStruct.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStruct.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_InitStruct);
DMA_Cmd(DMA2_Stream0, ENABLE);
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//??????12??
ADC_InitStructure.ADC_ScanConvMode = ENABLE;//?¨?è×????????????????¨???????????????à?¨???ò?è????ENABLE,
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//DISABLE; //????×??????? /???????ò??????×?????×??????????????è????????·???
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//??????????·????í????·?×???
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; //??????????·???????
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//??????????????×???????
ADC_InitStructure.ADC_NbrOfConversion = 2;//???¨?????ò???????ò×?????ADC?¨????????
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_3Cycles);//ADC?????¨??8?????ò?÷????1???ù???¨???????ù????
ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 2, ADC_SampleTime_3Cycles);//ADC?????¨??9?????ò?÷????2???ù???¨???????ù????
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
ADC_DMACmd(ADC1, ENABLE);
ADC_Cmd(ADC1, ENABLE);
ADC_SoftwareStartConv(ADC1); //?í??????×???
}[/mw_shl_code]
|