cancel
Showing results for 
Search instead for 
Did you mean: 

How to import a long array of float constants into a project

FredS
Senior

    Dear forum members,

I work on a project that repeatedly reads 3692 pixel intensity values from a linear CCD pixel-array. The readout process and export of the data via USB is working fine.

Now I want to enhance the application by multiplying each pixel value with its specific correction factor to compensate for the individual sensitivity. I struggle to find the right method to import the correction values from a text-file.

At first I tried to add a user include file that assigns the float values (in the range 0.90 to 1.10) to the array 'g_PixFactor' that is declared in the 'main.c' file. This approach produces errors like "re-definition of array 'g_PixFactor' ". I also tried to do the declaration and the assignment of the values in the include file, which gave other complaints.

 

My questions are:

   - Is the concept of importing values by an include file a workable method to solve my challenge? 

   - Can a more experienced forum member provide me the steps to get the correction values from a file assign to the float array?

 

I already found out I need to specify the float constants with 'f' as suffix to prevent interpretation as int value.

 

Some background: I work on a PC with Windows11 and just have done a clean install of STM32CUBEIDE32 v 1.19.0 after I experienced many strange errors in pieces of code that were fine before the last upgrade. The target HW is a STM32H723VG on a WeAct board.

 

As always, thanks in advance for spending time on my request,

greetings from the Netherlands,

                Fred Schimmel

2 REPLIES 2
TDK
Super User

If they are static, this will put them into FLASH where they can be read as needed:

// in floats.h:
extern const float gArray[1024];

// in floats.c:
const float gArray[1024] = {1, 2, 3, 4, ...};

// in any other *.c file you want to use them in:
#include "floats.h"

...

    float x = gArray[124];

 

If you feel a post has answered your question, please click "Accept as Solution".

   Hallo TDK,

Thanks for the very quick response.
There is one thing in your concept I don't understand. I want to import the values  into the project via a file that I create externally in the program that measured the correction values. Is the 'floats.c' file the one that does the import?

Greetings,

                  Fred Schimmel