在线时间2 小时
UID173698
ST金币0
蝴蝶豆0
注册时间2010-3-5
新手上路
- 最后登录
- 2018-5-31
|
a0a.1 0b0c
#define ADC3_DR_Address ((u32)0x40013C4C)
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;//ADC1和ADC2工作在独立模式
ADC_InitStructure.ADC_ScanConvMode = ENABLE; //使能扫描
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;//ADC转换工作在单次模式
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2;//定时器2的捕获比较2为转换外部触发
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//转换数据右对齐
ADC_InitStructure.ADC_NbrOfChannel = 10;//转换通道为通道1
ADC_Init(ADC3, &ADC_InitStructure); //初始化ADC
ADC_RegularChannelConfig(ADC3, ADC_Channel_1, 1, ADC_SampleTime_28Cycles5 );
ADC_RegularChannelConfig(ADC3, ADC_Channel_12, 2, ADC_SampleTime_28Cycles5 );
ADC_RegularChannelConfig(ADC3, ADC_Channel_8, 3, ADC_SampleTime_28Cycles5 );
ADC_RegularChannelConfig(ADC3, ADC_Channel_7, 4, ADC_SampleTime_28Cycles5 );
ADC_RegularChannelConfig(ADC3, ADC_Channel_11, 5, ADC_SampleTime_28Cycles5 );
ADC_RegularChannelConfig(ADC3, ADC_Channel_10, 6, ADC_SampleTime_28Cycles5 );
ADC_RegularChannelConfig(ADC3, ADC_Channel_13, 7, ADC_SampleTime_28Cycles5 );
ADC_RegularChannelConfig(ADC3, ADC_Channel_5, 8, ADC_SampleTime_28Cycles5 );
ADC_RegularChannelConfig(ADC3, ADC_Channel_6, 9, ADC_SampleTime_28Cycles5 );
ADC_RegularChannelConfig(ADC3, ADC_Channel_4, 10, ADC_SampleTime_28Cycles5 );
ADC_DMACmd(ADC3, ENABLE);//使能ADC3模块DMA
ADC_Cmd(ADC3, ENABLE);//使能ADC1
ADC_ResetCalibration(ADC3); //重置ADC1校准寄存器
while(ADC_GetResetCalibrationStatus(ADC3));//等待ADC1校准重置完成
ADC_StartCalibration(ADC3);//开始ADC1校准
while(ADC_GetCalibrationStatus(ADC3));//等待ADC1校准完成
ADC_ExternalTrigConvCmd(ADC3, ENABLE); ////设置外部事件为TIM2_CC2
DMA_DeInit(DMA2_Channel5);//复位DMA通道5
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC3_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC3ConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 10;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//当前存储器地址不变
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//定义外设数据宽度16位
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //定义存储器数据宽度16位
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA通道操作模式位环形缓冲模式
DMA_InitStructure.DMA_Priority = DMA_Priority_High;//DMA通道优先级高
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//禁止DMA通道存储器到存储器传输
DMA_Init(DMA2_Channel5, &DMA_InitStructure);
DMA_Cmd(DMA2_Channel5, ENABLE); //使能DMA通道5
DMA_ITConfig(DMA2_Channel5, DMA_IT_TC, ENABLE);
void DMA2_Channel4_5_IRQHandler(void)
{
DMA_ClearFlag(DMA2_FLAG_GL5 );
}
void Interrupts_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Channel4_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
} |
|