Shared data block

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

   

 

   

I want to use a shared data block between different c-files.

   

I'm using a 32 byte array, which I fill up with data from my I2C-bus in I2CHandler.c. The data will be displayed on a smart display. So, I try to send the data to the display in Display.c.

   

Therefore, I defined the variable in vars.h as:

   

static BYTE dataReceive[32];

   

The vars.h file is included in I2CHandler.c and Display.c. But somehow Display.c will not have the same data (all zeros) as I2CHandler.c (some random hex-data).

   

How can I fix this behavior?

   

The data is received, because if I send the data to the display in I2CHandler.c, then the correct data is shown. But I want to separate the different functions in different files.

   

Thanks in advance.

   

 

   

With kind regards,

   

 

   

Erik

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Do not define data in .h files, only declarations allowed here. Declare data as "extern" and define the data in main.c

   

 

   

Bob

View solution in original post

0 Likes
2 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Do not define data in .h files, only declarations allowed here. Declare data as "extern" and define the data in main.c

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi,

   

thats what I did now. I give the pointer to the data to each module and then it is possible to access the data by different modules.

   

But I thought it should be possible to share data declared in a e.g. General.h file. When defined as static, there should be only one declaration in memory.

   

Compiling results in no errors and warnings. But the data is not the same over the different modules (looks like it is declared multiple times) ?!?!?

   

Greetings,

   

Erik

0 Likes