The current AD value = 0x0FFF The current AD value = 0x0000 The current AD value = 0x0000 The current AD value = 0x0000 The current AD value = 0x0000 The current AD value = 0x0FFF The current AD value = 0x0000 The current AD value = 0x0000 The current AD value = 0x0000 The current AD value = 0x0000 The current AD value = 0x0000 The current AD value = 0x0FFF
目前遇到的问题是什么?
融合已经完成,目前只做出一个通道的ADC,用的是有DMA的,ADC2,通道2,转换结果AD_value=ADC_GetConversionValue(ADC2);然后无限发射给另一个NRF,NRF通过转USB虚拟串口发给上位机,上位机也能正常接收到转换结果,但是不知双通道的ADC怎么做,想加个通道1,需要怎么改…… GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
……………………
ADC_InitStructure.ADC_NbrOfChannel = 2;
……………………
ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC2, ADC_Channel_2, 2, ADC_SampleTime_55Cycles5);
……………………
AD_value=ADC_GetConversionValue(ADC2) 是这样么?
可是这样接收到的数据是这样的
The current AD value = 0x0FFF
The current AD value = 0x0000
The current AD value = 0x0000
The current AD value = 0x0000
The current AD value = 0x0000
The current AD value = 0x0FFF
The current AD value = 0x0000
The current AD value = 0x0000
The current AD value = 0x0000
The current AD value = 0x0000
The current AD value = 0x0000
The current AD value = 0x0FFF
[ 本帖最后由 mahe6562 于 2011-8-15 23:10 编辑 ](我一个脚测5V一个脚测0v)
GPIO 配置
// AD1 AD2 AD3 AD4
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5|GPIO_Pin_6 |GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
/* Initializes the ADC1 peripheral configuration*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC_Mode value
ADC_InitStructure.ADC_ScanConvMode = ENABLE; //ADC_ScanConvMode value
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //ADC_ContinuousConvMode value
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2; //ADC_ExternalTrigConv value
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADC_DataAlign value
ADC_InitStructure.ADC_NbrOfChannel = ADC_ScanCh; //ADC_NbrOfChannel value
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_13Cycles5); //pin: PC4
ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 2, ADC_SampleTime_13Cycles5); //pin: PC5
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 3, ADC_SampleTime_13Cycles5); //pin: PB0
ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 4, ADC_SampleTime_13Cycles5); //pin: PB1
ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 5, ADC_SampleTime_55Cycles5); //temperature
ADC_TempSensorVrefintCmd(ENABLE);
ADC_DMACmd(ADC1, ENABLE);
ADC_ExternalTrigConvCmd(ADC1, ENABLE);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
}
void DMA_Configuration(void)
{
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //DMA_PeripheralBaseAddr value
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_ConvertValueTab; //DMA_MemoryBaseAddr value
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //DMA_DIR value
DMA_InitStructure.DMA_BufferSize = ADC_ScanCh*ADC_ConvertNum;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //DMA_PeripheralInc value
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //DMA_MemoryInc value
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //DMA_PeripheralDataSize value
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //DMA_MemoryDataSize value
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //DMA_Mode value
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMA_Priority value
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //DMA_M2M value
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
//DMA_Cmd(DMA1_Channel1, ENABLE);
}
注意关DMA与AD的顺序
}
一周热门 更多>