F411 Nucleo Board ADC Issues
I tried to use ADC in F411 to read two ADC inputs.
My hardware is a F411-Nucleo board; my IDE is CubeIDE.
The followings are my ADC settings in IDE:
- I use 2 channels in ADC1 (IN1, IN4)
- I also use DMA to obtain ADC results.
I use
volatile uint16_t adc_reading[2]to store the 2 readings.
Here is the code in the while loop of main.c
while (1)
{
adc_read_complete = 0;
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_reading, adc_ch_cnt);
while(adc_read_complete == 0);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
sprintf(uart2_str, "\t%d %d\n", adc_reading[0], adc_reading[1]);
HAL_UART_Transmit(&huart2, (uint8_t *)uart2_str, strlen(uart2_str), 999);
HAL_Delay(2500);
}adc_ch_cnt is 2.
I have two problems:
- Only adc_reading[0] has a valid reading; adc_reading[1] is always 0; even I define it as uint32_t variable and change data length as WORD. That valid reading corresponds to the voltage applied to IN4/PA4.
- The valid reading is only 8 bits long, instead of 12 bits; meaning value is 254~255 when I applied 3.3v to PA4 pin.
