新手上路
- 积分
- 41
- 金钱
- 41
- 注册时间
- 2019-11-16
- 在线时间
- 14 小时
|
本帖最后由 syflg 于 2024-11-6 11:52 编辑
STM32F407 ADC采样DMA传送数据到外部SRAM
1.定义到内部存储器工作正常,ADC采样的数据可以在内存中看到
2.定义到外部存储器,只有第一个SRAM数据变化一次,数值还不对
3.在main主程序里读写外部SRAM工作正常
4.外部SRAM读写速度18M,ADC采样速度2.4M,应该不是这个问题吧?
哪位大侠能指点迷津一下
extern u16 adc_buf[48000];
//extern u16 adc_buf[48000]__attribute__((at(0X68000000)));
void Adc_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_InitTypeDef ADC_InitStructure;
DMA_InitTypeDef DMA_Initfjh;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_DMA2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1|RCC_APB2Periph_ADC2, ENABLE); //
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;//
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//­
GPIO_Init(GPIOB, &GPIO_InitStructure);//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //
GPIO_Init(GPIOB, &GPIO_InitStructure);//
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,ENABLE); // RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,DISABLE); //
DMA_Initfjh.DMA_Channel = DMA_Channel_0;
DMA_Initfjh.DMA_PeripheralBaseAddr = ADC_CDR_ADDR; //
DMA_Initfjh.DMA_Memory0BaseAddr = (u32)adc_buf; //
DMA_Initfjh.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_Initfjh.DMA_BufferSize = 48000; //
DMA_Initfjh.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //
DMA_Initfjh.DMA_MemoryInc = DMA_MemoryInc_Enable; //
DMA_Initfjh.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//
DMA_Initfjh.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //
DMA_Initfjh.DMA_Mode = DMA_Mode_Circular; //
DMA_Initfjh.DMA_Priority = DMA_Priority_High;//
DMA_Initfjh.DMA_FIFOMode = DMA_FIFOMode_Enable;//Disable; //
DMA_Initfjh.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;//
DMA_Initfjh.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_Initfjh.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_Initfjh);
DMA_Cmd(DMA2_Stream0, ENABLE);
ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult;//
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;//
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1; //
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;//
ADC_CommonInit(&ADC_CommonInitStructure);//
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//
ADC_InitStructure.ADC_ScanConvMode =DISABLE;//
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//
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 = 1;//
ADC_Init(ADC1, &ADC_InitStructure);//
ADC_Init(ADC2, &ADC_InitStructure);//
ADC_RegularChannelConfig(ADC1,ADC_Channel_8,1,ADC_SampleTime_3Cycles);
ADC_RegularChannelConfig(ADC2,ADC_Channel_9,1,ADC_SampleTime_3Cycles);
ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);
//ADC_DMARequestAfterLastTransferCmd(ADC1,ENABLE); //
//ADC_DMACmd(ADC1, ENABLE);//
ADC_Cmd(ADC1, ENABLE);//
ADC_Cmd(ADC2, ENABLE);//
ADC_SoftwareStartConv(ADC1);//
ADC_SoftwareStartConv(ADC2);//
}
|
|