|
大家好,关于ADC问题请教大家: 1)我要用到20通道AD,选的芯片是STM32F103ZCT6,用到ADC3、ADC1,设置如下:
void ADC3_Configuration(void) { ADC_InitTypeDef ADC_InitStructure; ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC1和ADC3工作在独立模式 ADC_InitStructure.ADC_ScanConvMode = ENABLE; //模数转换工作在扫描模式(多通道) ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //模数转换工作在连续模式 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //转换由软件而不是外部触发启动 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADC数据右对齐 ADC_InitStructure.ADC_NbrOfChannel = 9; //顺序进行规则转换的ADC通道的数目 ADC_Init(ADC3, &ADC_InitStructure); //根据ADC_InitStructure中指定的参数初始化外设ADC3的寄存器 // ADC_Init(ADC1, &ADC_InitStructure); //根据ADC_InitStructure中指定的参数初始化外设ADC1的寄存器 //设置指定ADC的规则组通道,设置它们的转化顺序(与原理图上的AI序号一致)和采样时间(取最大值) ADC_RegularChannelConfig(ADC3, ADC_Channe3_4, 1, ADC_SampleTime_239Cycles5);//AI1,PF6,Pin18 ADC_RegularChannelConfig(ADC3, ADC_Channe3_5, 2, ADC_SampleTime_239Cycles5);//AI2,PF7,Pin19 ADC_RegularChannelConfig(ADC3, ADC_Channe3_6, 3, ADC_SampleTime_239Cycles5);//AI3,PF8,Pin20 ADC_RegularChannelConfig(ADC3, ADC_Channe3_7, 4, ADC_SampleTime_239Cycles5);//AI4,PF9,Pin21 ADC_RegularChannelConfig(ADC3, ADC_Channe3_10, 5, ADC_SampleTime_239Cycles5);//AI5,PC0,Pin26 ADC_RegularChannelConfig(ADC3, ADC_Channe3_11, 6, ADC_SampleTime_239Cycles5);//AI6,PC1,Pin27 ADC_RegularChannelConfig(ADC3, ADC_Channe3_12, 7, ADC_SampleTime_239Cycles5);//AI7,PC2,Pin28 ADC_RegularChannelConfig(ADC3, ADC_Channe3_13, 8, ADC_SampleTime_239Cycles5);//AI8,PC3,Pin29 ADC_RegularChannelConfig(ADC3, ADC_Channe3_0, 9, ADC_SampleTime_239Cycles5);//AI9,PA0,Pin34 ADC_DMACmd(ADC3, ENABLE); //使能ADC3的DMA请求 // ADC_DMACmd(ADC1, ENABLE); //使能ADC1的DMA请求 ADC_Cmd(ADC3, ENABLE); //使能ADC3 // ADC_Cmd(ADC1, ENABLE); //使能ADC1 // ADC_TempSensorVrefintCmd(ENABLE); //使能温度传感器和内部参考电压通道
ADC_ResetCalibration(ADC3); //重置ADC3的校准寄存器 while(ADC_GetResetCalibrationStatus(ADC3)); //获取ADC重置校准寄存器的状态并等待其值变为0(校准寄存器已初始化) // ADC_ResetCalibration(ADC1); //重置ADC1的校准寄存器 // while(ADC_GetResetCalibrationStatus(ADC1)); //获取ADC重置校准寄存器的状态并等待其值变为0(校准寄存器已初始化)
ADC_StartCalibration(ADC3); //开始ADC3的校准状态 while(ADC_GetCalibrationStatus(ADC3)); //获取ADC校准寄存器的状态并等待其值变为0(已完成校准) // ADC_StartCalibration(ADC1); //开始ADC1的校准状态 // while(ADC_GetCalibrationStatus(ADC1)); //获取ADC校准寄存器的状态并等待其值变为0(已完成校准)
ADC_SoftwareStartConvCmd(ADC3, ENABLE); //使能ADC3的软件转换启动功能 // ADC_SoftwareStartConvCmd(ADC1, ENABLE); //使能ADC1的软件转换启动功能 }
void ADC1_Configuration(void) { ADC_InitTypeDef ADC_InitStructure; ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC1和ADC3工作在独立模式 ADC_InitStructure.ADC_ScanConvMode = ENABLE; //模数转换工作在扫描模式(多通道) ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //模数转换工作在连续模式 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //转换由软件而不是外部触发启动 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADC数据右对齐 ADC_InitStructure.ADC_NbrOfChannel = 11; //顺序进行规则转换的ADC通道的数目 // ADC_Init(ADC3, &ADC_InitStructure); //根据ADC_InitStructure中指定的参数初始化外设ADC3的寄存器 ADC_Init(ADC1, &ADC_InitStructure); //根据ADC_InitStructure中指定的参数初始化外设ADC1的寄存器 //设置指定ADC的规则组通道,设置它们的转化顺序(与原理图上的AI序号一致)和采样时间(取最大值) ADC_RegularChannelConfig(ADC1, ADC_Channe1_1, 1, ADC_SampleTime_239Cycles5);//AI10,PA1,Pin35 ADC_RegularChannelConfig(ADC1, ADC_Channe1_2, 2, ADC_SampleTime_239Cycles5);//AI11,PA2,Pin36 ADC_RegularChannelConfig(ADC1, ADC_Channe1_3, 3, ADC_SampleTime_239Cycles5);//AI12,PA3,Pin37 ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 4, ADC_SampleTime_239Cycles5);//AI13,PA4,Pin40 ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 5, ADC_SampleTime_239Cycles5);//AI14,PA5,Pin41 ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 6, ADC_SampleTime_239Cycles5);//AI15,PA6,Pin42 ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 7, ADC_SampleTime_239Cycles5);//AI16,PA7,Pin43 ADC_RegularChannelConfig(ADC1, ADC_Channel_14,8, ADC_SampleTime_239Cycles5);//AI17,PC4,Pin44 ADC_RegularChannelConfig(ADC1, ADC_Channel_15,9, ADC_SampleTime_239Cycles5);//AI18,PC5,Pin45 ADC_RegularChannelConfig(ADC1, ADC_Channel_8,10, ADC_SampleTime_239Cycles5);//AI19,PB0,Pin46 ADC_RegularChannelConfig(ADC1, ADC_Channel_9,11, ADC_SampleTime_239Cycles5);//AI20,PB1,Pin47 // ADC_DMACmd(ADC3, ENABLE); //使能ADC3的DMA请求 ADC_DMACmd(ADC1, ENABLE); //使能ADC1的DMA请求 // ADC_Cmd(ADC3, ENABLE); //使能ADC3 ADC_Cmd(ADC1, ENABLE); //使能ADC1 // ADC_TempSensorVrefintCmd(ENABLE); //使能温度传感器和内部参考电压通道
// ADC_ResetCalibration(ADC3); //重置ADC3的校准寄存器 // while(ADC_GetResetCalibrationStatus(ADC3)); //获取ADC重置校准寄存器的状态并等待其值变为0(校准寄存器已初始化) ADC_ResetCalibration(ADC1); //重置ADC1的校准寄存器 while(ADC_GetResetCalibrationStatus(ADC1)); //获取ADC重置校准寄存器的状态并等待其值变为0(校准寄存器已初始化)
// ADC_StartCalibration(ADC3); //开始ADC3的校准状态 // while(ADC_GetCalibrationStatus(ADC3)); //获取ADC校准寄存器的状态并等待其值变为0(已完成校准) ADC_StartCalibration(ADC1); //开始ADC1的校准状态 while(ADC_GetCalibrationStatus(ADC1)); //获取ADC校准寄存器的状态并等待其值变为0(已完成校准)
// ADC_SoftwareStartConvCmd(ADC3, ENABLE); //使能ADC3的软件转换启动功能 ADC_SoftwareStartConvCmd(ADC1, ENABLE); //使能ADC1的软件转换启动功能 }
出现错误说这些量没定义: compiling YFSIGNAL_MAIN_V1.c... ..SourceYFSIGNAL_MAIN_V1.c(305): error: #20: identifier "ADC3ConvertedValue" is undefined ..SourceYFSIGNAL_MAIN_V1.c(340): error: #20: identifier "ADC_Channe3_4" is undefined ..SourceYFSIGNAL_MAIN_V1.c(341): error: #20: identifier "ADC_Channe3_5" is undefined ..SourceYFSIGNAL_MAIN_V1.c(342): error: #20: identifier "ADC_Channe3_6" is undefined ..SourceYFSIGNAL_MAIN_V1.c(343): error: #20: identifier "ADC_Channe3_7" is undefined ..SourceYFSIGNAL_MAIN_V1.c(344): error: #20: identifier "ADC_Channe3_10" is undefined ..SourceYFSIGNAL_MAIN_V1.c(345): error: #20: identifier "ADC_Channe3_11" is undefined ..SourceYFSIGNAL_MAIN_V1.c(346): error: #20: identifier "ADC_Channe3_12" is undefined ..SourceYFSIGNAL_MAIN_V1.c(347): error: #20: identifier "ADC_Channe3_13" is undefined ..SourceYFSIGNAL_MAIN_V1.c(348): error: #20: identifier "ADC_Channe3_0" is undefined ..SourceYFSIGNAL_MAIN_V1.c(409): error: #20: identifier "ADC_Channe1_1" is undefined ..SourceYFSIGNAL_MAIN_V1.c(410): error: #20: identifier "ADC_Channe1_2" is undefined ..SourceYFSIGNAL_MAIN_V1.c(411): error: #20: identifier "ADC_Channe1_3" is undefined
2)ADC的连续模式适合用在采什么样的信号:它的单次模式指的是把所有通道(如20通道)都转换一次然后停止,还是只在一个通道上转换一次就停了?
|
|