cancel
Showing results for 
Search instead for 
Did you mean: 

Using STVD with Cosmic C compiler. A bit in a global variable is being set unexpectedly. How can I prevent that?

EBogo.1
Associate II

I am modifying code for the NUCLEO-8S208RB used with X-NUCLEO-NFC05A1 NFC reader. The code was originally developed by ST. I need to modify it for my own application. So, I created my own global variables and gotten rid of unnecessary code. So far everything is working. But a bit in one of those variables is being set somewhere outside my code. The variable in question is a bit field, declared thus:

typedef union //Defining new type as this union

{ //of either byte or 8 bits. This is

struct //used for general status.

{

unsigned scanned:1; //Bit 0: NFC tag has been scanned.

unsigned I2Cready:1; //Bit 1: I2C buffer is ready to be read by the Latch.

unsigned dummy2:1; //Bit 2: unused, always 0.

unsigned dummy3:1; //Bit 3: unused, always 0.

unsigned dummy4:1; //Bit 4: unused, always 0.

unsigned dummy5:1; //Bit 5: unused, always 0.

unsigned dummy6:1; //Bit 6: unused, always 0.

unsigned dummy7:1; //Bit 7: unused, always 0.

}bits; //Name of the bits in this byte structure.

unsigned char byte; //Complete byte form.

}StatusStruct; //Name of this new type.

volatile StatusStruct genStat; //This is the general status register, used as a bitfield.

One of the unused bits, dummy3, is being set. Declaring this variable as volatile didn't help. Disabling optimizations didn't help. Creating dummy piece of code to use this bit didn't help. It looks like some boolean variable outside my code in some function originally from ST uses this bit. How can I prevent that? What other unexpected variable changes can I expect from this compiler?

Thank you,

Eric Bogomolny.

1 REPLY 1
EBogo.1
Associate II

Well, I have a bit of an egg on my face: that bit was being set because of my bug. I was overflowing one of my buffers. However, before I removed the original code I wasn’t using, my variables really were getting cleared somewhere outside my code. So, there still might be some issue.