问题如题所示,请问如何用stm32L011芯片配置成多通道ADC采样,比如PA0,PA1两路采样,我的配置如下:
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t value_L;
uint8_t value_H;
uint8_t i = 0;
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
USART_SendData(USART2,"a");
USART_SendData(USART2,"a");
USART_SendData(USART2,"a");
//HAL_ADC_Start_DMA(&hadc, (uint32_t*)&uhADCxConvertedValue, 1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
for(i=0;i<2;i++)
{
HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc,0xffff);//wait adc
uhADCxConvertedValue[i]=HAL_ADC_GetValue(&hadc);
//printf("------ch:%d--%d-------\r\n",i,adcBuf[i]);
value_H = (uhADCxConvertedValue[i] & 0xff00 ) >> 8;
value_L = (uhADCxConvertedValue[i] & 0x00ff );
LL_USART_TransmitData8(USART2, value_L);
LL_USART_TransmitData8(USART2, value_H);
}
HAL_ADC_Stop(&hadc);
LL_mDelay(1000);
}
/* USER CODE END 3 */
}
ADC init function is below
/* ADC init function */
void MX_ADC_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc.Instance = ADC1;
hadc.Init.OversamplingMode = DISABLE;
hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.SamplingTime = ADC_SAMPLETIME_79CYCLES_5;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DiscontinuousConvMode = ENABLE;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerFrequencyMode = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
if (HAL_ADC_Init(&hadc) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = 0;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = 1;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
但是只能采集到PA0的电压,
高手们请问stm32L011的dma配置和F103的配置哪里一样啊?
|