Peter1
Peter1

Reputation: 97

How can I "live watch" a variable in a union when debugging in IAR Workbench

I am new to programming but need some help on debugging in IAR.

I have created a union with a floating point, an array of 4 uint8 and 4 uint8 variables and that works fine, I can set the float and the other values are correct when printed to the IO terminal.

I want to monitor the variables in the live watch window when debugging but it says "Error, cannot take address of Test" (Test is the name of the union).

Is there way to do this, besides looking at the memory location ? Would it work if all variables was 32bit, I will test this when I get to the office in a couple of hours?

union Eeprom
{
struct
{
uint8_t Byte1;
uint8_t Byte2;
uint8_t Byte3;
uint8_t Byte4;
};
float floatvalue;
uint8_t Array[4];
};

int main(void)
{
  union Eeprom Test;

  Test.floatvalue = 23.1;

printf("floatvalue %3.2f \n Byte1 %x\n Byte2 %x\n Byte3 %x\n Byte4 %x\n 
   Array[0] %x\n Array[1] %x\n Array[2] %x\n Array[3] %x\n",      Test.floatvalue, 
   Test.Byte1, Test.Byte2, Test.Byte3, Test.Byte4, 
   Test.Array[0], Test.Array[1], Test.Array[2], Test.Array[3]);

The Live watch window looks like this: enter image description here

Output looks like this: enter image description here

Any help will be appreciated

Upvotes: 3

Views: 6125

Answers (2)

Peter1
Peter1

Reputation: 97

So, the code is now:

union Eeprom
{
struct
{
uint8_t Byte1;
uint8_t Byte2;
uint8_t Byte3;
uint8_t Byte4;
};
float floatvalue;
uint8_t Array[4];
};

union Eeprom Test;

int main(void)
{

  Test.floatvalue = 23.1;

printf("floatvalue %3.2f \n Byte1 %x\n Byte2 %x\n Byte3 %x\n Byte4 %x\n 
   Array[0] %x\n Array[1] %x\n Array[2] %x\n Array[3] %x\n",      Test.floatvalue, 
   Test.Byte1, Test.Byte2, Test.Byte3, Test.Byte4, 
   Test.Array[0], Test.Array[1], Test.Array[2], Test.Array[3]);

And the Live watch windows looks like this:

enter image description here

Upvotes: 0

user694733
user694733

Reputation: 16039

Here's what my IAR manual says:

LIVE WATCH WINDOW

The Live Watch window—available from the View menu—repeatedly samples and displays the value of expressions while your application is executing. Variables in the expressions must be statically located, such as global variables.

Variable union Eeprom Test; is declared inside the main function, so it has automatic storage duration. These are placed on stack and don't have predefined address, which makes it harder for debugger to hold on to. Thus they cannot be used with Live Watch.

Move Test outside of main, or declare it with static.

Upvotes: 2

Related Questions