我用淘淘科技的STM332F407VGT6开发板 ,通过板子上DA发送一个幅值为3V、周期为1ms的正弦波,然后用AD采集一个周期的256点,之后调用DSP库中的FFT分析,然后在LCD上显示。但是在调程序的时候,对一下几个问题仍模糊:1、不知道DMA设置对不对; 2 不知道定时器设置对不对;3 不知道ADC采样时间设置对不对 ;4 不知道中断处理对不对uint16_t j=0,k=0;
uint16_t capture = 0;
extern uint16_t ADC1ConvertedValue[512];
float32_t adc_Value[256*2];
uint16_t adc_Count=0;
void TIM3_IRQHandler(void)
{
// if (TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET)
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
j++;
ADC_SoftwareStartConv(ADC1);
if(j>=40000) //400
{
j=0;
GPIO_ToggleBits(GPIOD,GPIO_Pin_12);
LCD_ShowNum(25,75,78);
}
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
}
}
//bool adc_sample = false;
void DMA2_Stream0_IRQHandler(void)
{
uint16_t i=0;
if(DMA_GetFlagStatus(DMA2_Stream0,DMA_FLAG_TCIF0)!= RESET)
{
ADC_Cmd(ADC1, DISABLE);
GPIO_ToggleBits(GPIOD,GPIO_Pin_13);
// GPIO_SetBits(GPIOD,GPIO_Pin_13);
// unsigned int aa;
// aa=0;
for(adc_Count=0;adc_Count<256*2;)
{
adc_Value[adc_Count++] = ADC1ConvertedValue[i]&0x0000ffff;
adc_Value[adc_Count++] = 0;
adc_Value[adc_Count++] = ADC1ConvertedValue[i++]>>16;
adc_Value[adc_Count++] = 0;
}
FFT();
adc_Count=0;
ADC1->SR = 0;
// DMA_Config();
ADC_Cmd(ADC1, ENABLE);
}
DMA_ClearITPendingBit(DMA2_Stream0,DMA_IT_TCIF0);
}
弄了几天还没搞定,希望大神帮我看看程序,指点一下void DMA_Config(void)
{
// RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
/* DMA2 Stream0 channel0 configuration **************************************/
DMA_DeInit(DMA2_Stream0);
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC1ConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; ///////// ??????????????
DMA_InitStructure.DMA_BufferSize = 256;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //
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_Cmd(DMA2_Stream0, ENABLE);
/* Enable DMA request after last transfer (Single-ADC mode) */
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
//使能DMA中断
DMA_ITConfig(DMA2_Stream0,DMA_IT_TC , ENABLE);
}
|