Skip to main content
artvolk
Associate III
Jun 6, 2011 7:05 PM UTC
Question

Assign register value to variable

Posted on June 06, 2011 at 21:05

Good day!

I'm trying to assign register value to a variable in COSMIC C. I've tried the obvious way first, but it doesn't work:

uint8_t test = 0;

...

test = CLK->SWCR; // define from stm8s.h

and

uint8_t test = 0;

...

test = CLK_SWCR; // define from ''C:\Program Files\COSMIC\CXSTM8_32K\Hstm8\iostm8s.h''

When I run my program in Debug mode and create a watch for 'test' variable it is always zero.

What can be wrong?

Thanks in advance!
    This topic has been closed for replies.

    2 replies

    luca239955_stm1_st
    Associate
    Jun 7, 2011 6:31 AM UTC
    Posted on June 07, 2011 at 08:31

    Hi,

    one possibility is that your variable ''test'' is optimized away: declare it volatile as a minimum.

    Also check that the hardware register you are reading does not actually contain zero.

    Hope it helps.

    Luca

    artvolk
    artvolkAuthor
    Associate III
    Jun 7, 2011 8:54 PM UTC
    Posted on June 07, 2011 at 22:54

    Thank you a lot, it seems it was really optimized, despite it was builded in Debug mode.

    'volatile' does the trick, thanks a lot!