相关代码如下: vu16 ADC_ConvertedValueROB[11];
void ADC_ConfigruationROB(void) { ADC_InitTypeDef ADC_InitStructure; DMA_InitTypeDef DMA_InitStructure; /* DMA channel1 configuration ----------------------------------------------*/ DMA_DeInit(DMA_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_ConvertedValueROB; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 11; 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_M2M = DMA_M2M_Disable; DMA_Init(DMA_Channel1, &DMA_InitStructure); /* Enable DMA channel1 */ DMA_Cmd(DMA_Channel1, ENABLE); /* ADC1 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 11; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel10 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 3, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 4, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 5, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 6, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 7, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 8, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 9, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 10, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 11, ADC_SampleTime_55Cycles5); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
INT32U ADC_GetConvertValueROB(INT8U ADC_GROUP) { return ADC_ConvertedValueROB[ADC_GROUP-1];
}
存在的问题: 在没有操作系统的环境下用此段代码,发觉: ADC_ConvertedValueROB[0] 对应为 ADC_Channel_0 的值 ADC_ConvertedValueROB[1] 对应为 ADC_Channel_1 的值 。。。 ADC_ConvertedValueROB[10] 对应为 ADC_Channel_9 的值
上述代码对应是我们想象中的,试验结果也是对的。
但是当这段代码放入另一个环境(带有操作系统)时发觉: ADC_ConvertedValueROB[0] 对应为 ADC_Channel_9 的值(为上述代码ADC_RegularChannelConfig()最后一行) ADC_ConvertedValueROB[1] 对应为 ADC_Channel_0 的值 。。。 ADC_ConvertedValueROB[10] 对应为 ADC_Channel_14 的值
规律是都后退了一位,为什么会这样?现在要实时读取11个通道的值,有什麽办法?
说明: 关于初始启动代码 RCC_ConfigurationROB(); NVIC_ConfigurationROB();
GPIO_ConfigurationROB();
在两个环境中都是同样的代码 |
|