2022-04-25 03:58 AM
I hope someone can help me with my problem. In a recent post I talked about my problems getting DMA work with the ADC. This does work, sort of.
Now to my problem: The ADC is triggered by a timer update event. Then the data is transferred via DMA to a buffer. The problem is, that the values in the DMA buffer are random (?) values. I verified with an osilloscope that the timings of the measurements are correct:
The yellow line is toggled after the buffer is filled completely, the blue line is the signal to be measured. The sampling frequency (and the frequency of the timer) is 500kHZ, so well within the ADC spec (event the slow ones have a sample rate of 1MHz). The buffer has a size of 256, so the frequency of the yellow line fits this as well.
This is what the first 100 values in the ADC buffer actually look like:
Looks like a sine wave with a really low sample rate, doesn't it? But if the
HAL_ADC_ConvCpltCallback-interrupt is called at the right time, then this should be the first sine wave. So it makes no sense.
The DAC is working though, this is what a constant 3.2V looks like:
And this happens if I leave the input floating:
I'm a bit lost at the moment. I tried so many different things in the last two days, but nothing worked. If someone has any idea, I'd highly appreciate it.
Some more info:
- the mcu: STM32H743ZI (on a nucleo board)
- cubeIDE 1.7.0 (1.9.0 completely breaks the ADC/DMA combo)
- the timer, dma and adc setup:
- I don't think my code is that relevant here, but here in this line is the setup of the DMA/ADC: https://github.com/TimGoll/masterthesis-lcr_driver/blob/main/Core/Code/Logic/AnaRP.c#L14 (the remaining adc/dma logic is in this file as well and here is the timer setup: https://github.com/TimGoll/masterthesis-lcr_driver/blob/main/Core/Code/Threads/AnalogIn.c#L10
- the autogenerated setup can be found in the main.c: https://github.com/TimGoll/masterthesis-lcr_driver/blob/main/Core/Src/main.c
---
I posted the same question on Reddit: https://www.reddit.com/r/embedded/comments/ubh04v/stm32_adc_dma_problems/
There a helpful commenter noticed that there is nothing in the auto-generated code that links the ADC to the DMA. Maybe the timings are completely off? However I'm not so sure about this because the interrupt timing is right.
-----
UPDATE [solved]:
There was no bug at all. Thanks to everyone and their great ideas I learned today that a breakpoint does not stop DMA and interrupts. Therefore the data that the debugger got was a random mess from multiple cycles. Here is how it looks now:
Solved! Go to Solution.
2022-04-25 01:38 PM
This is a good point many people on reddit also made. I will test this tomorrow. I hope you're right and it works. If it does, at least I learned something new!
2022-04-25 05:42 PM
Ahh, indeed it's 2-dimensional. But then the array element of the first dimension is also an array and adding & will not change anything. So in this case all of those versions are the same.
https://stackoverflow.com/questions/2528318/how-come-an-arrays-address-is-equal-to-its-value-in-c
The & operator by itself cannot create a double pointer. One has to create an intermediate pointer variable for storing the second level pointer.