2021-08-14 05:46 AM
I want to convert a bunch of uint16_t values from an ADC into floating point voltages. For this I use a for loop to loop through the uint16_t array and write the values to a float array. But the float array remains 0 as if no assignment is ever made. Outside of the for loop the conversion works. And when I step through the program with the debugger, I see reasonable float values but they do not end up being written to the array. Why?
the temp float value is 1.847
the temporary index is 0
but the array at index 0 is not 1.847
2021-08-14 06:18 AM
we'd have to look at the code, as a guess.
and need to know if the processor has cache
and need to know if a DMA is somehow involved in the process.
but its likely you are not reading the right memory or not writing to the right memory
need to see the code
2021-08-14 06:22 AM
STM32f373re does not have a cache afaik.
I just posted the main file.
the uint16_t array is indeed being filled by the DMA.
I am confused because the conversion works outside of a for loop.
2021-08-14 06:36 AM
For DMA the memory array needs to be volatile so as not to be folded by optimization, the DMA also needs to have completed prior to working being done on the data it has fetched.
2021-08-14 07:11 AM
check the DMA flag or DMA counter for completion,
then enter the for loop
2021-08-15 12:44 AM
I was able to resolve it, without knowing what cause this. Either way, my code is now much cleaner and easier to read
2021-08-15 02:30 AM
> I was able to resolve it, without knowing what cause this.
Then you did not resolve it.
If a global variable (adc_voltages[]) has nonzero value before you wrote into it the first time, it means either incorrect software wrote into it (incorrect pointer or out-of-bounds index to array), or incorrectly set DMA wrote into it.
You should be able to catch the culprit using data breakpoints (a.k.a. watchpoints). If there's no break and the data are changed, then it's DMA.
JW