2024-09-02 07:17 AM - edited 2024-09-02 07:19 PM
I am trying to use ADC with DMA on STM32H743XI. I set up ADC1 IN7~IN9 and use three uint16_t to store their converted values. I use DMA2 Stream 0 to transfer data. CPU ICache and DCache as well as MPU are disabled. ADC Clock Mux is set to PLL2P 50MHz. SYSCLK is set to 480MHz. I also set up a USART1 to print results.
Below are some other settings on STM32CubeMX:
ADC settings:
ADC DMA settings:
This is how I define the result array:
uint16_t ADC_Values[ADC_N_CHANNELS] __attribute__((section(".ARM.__at_0x24000000")));
where `ADC_N_CHANNELS` is 3.
After initializing peripherals, I add the code below to the main function above the infinite while loop:
HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)ADC_Values, ADC_N_CHANNELS);
In the while loop I print the values of `ADC_Values` and delay for a sec. But it seems that the values of the array are always over 10,000, which are obviously abnormal. What's wrong with it? Any help will be highly appreciated.
2024-09-02 07:25 AM
Hello,
I think you need to give more details and more code or if possible to attach your project.
2024-09-02 07:30 AM
> But it seems that the values of the array are always over 10,000, which are obviously abnormal.
Why would that be obvious?
What is connected to the respective pins?
What hardware are you using, a "known good" board like Nucleo/Disco, or your own?
How are those pins set (i.e. read out and check/post relevant GPIO registers content)?
JW
2024-09-02 07:20 PM
Hello, I have just added the compressed project to this post.
2024-09-02 07:24 PM
> Why would that be obvious?
I have set the resolution of ADC to 12-bit. I think the converted value should be less than 4096.
> What is connected to the respective pins?
I connected the pin of ADC1 IN8 (I am sorry I forget which pin it is) to 3V3 on the board, others don't connect with any.
> What hardware are you using, a "known good" board like Nucleo/Disco, or your own?
A board from a local company, not from ST.
> How are those pins set (i.e. read out and check/post relevant GPIO registers content)?
I am sorry that I have no appropriate environment to check the registers. I will attach the content ASAP.
2024-09-03 12:11 AM
> I have set the resolution of ADC to 12-bit. I think the converted value should be less than 4096.
Without oversampling, yes.
Read out the ADC registers content and check if it's set properly in that respect.
JW
2024-09-03 02:30 AM
Do you mean that I should look at the ADC1 configuration register to check if the bits of oversampling are set right?
I have read the datasheet, and find that (if I haven't made mistakes) the base address of ADC1 is 0x40022000, the ADC_CFGR2 register has an offset of 0x10, and that the OVSS register is located at bits 8:5. So I looked at the memory at 0x40022010 but it showed 0x00. Does it mean that the value of OVSS register is 0 (which means oversampling is disabled)?
2024-09-03 03:02 AM
> I have read the datasheet, and find that (if I haven't made mistakes) the base address of ADC1 is 0x40022000, the ADC_CFGR2 register has an offset of 0x10, and that the OVSS register is located at bits 8:5.
This is simpler to do using a debugger.
> Does it mean that the value of OVSS register is 0 (which means oversampling is disabled)?
Yes. Similarly, you should check if the 12-bit mode is indeed set; and when at it, observe the data register too.
I don't use the 'H7, maybe there's some other explanation for your observation.
JW