cancel
Showing results for 
Search instead for 
Did you mean: 

float values of array are not assigned during a for loop

Mnemocron
Associate III

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

0693W00000D2U7SQAV.png 

the temporary index is 0

0693W00000D2U7XQAV.png 

but the array at index 0 is not 1.847

0693W00000D2U7cQAF.png 

6 REPLIES 6
T J
Lead

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

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.

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
T J
Lead

check the DMA flag or DMA counter for completion,

then enter the for loop

https://stackoverflow.com/questions/68783394/float-values-of-array-are-not-assigned-during-a-for-loop-stm32-arm-none-eabi

I was able to resolve it, without knowing what cause this. Either way, my code is now much cleaner and easier to read

> 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