Keil- ARM compiler Write and read from absolute address

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Keil- ARM compiler Write and read from absolute address

Jump to solution
2,153 Views
aswinprabhu
Contributor III

Hi,

Can someone specify ways to a) write to and b) read from, an absolute address for ARM compiler? Microcontroller is LPC54628.

Issue:

A global variable 'var' prints a certain value to serial terminal when called from main function but when this value is printed from inside an Interrupt Service Routine, it shows up as 0. If I change the initializing value for this variable to something else, say 100, then it will print 100. Can't figure out why. Hence thinking of accessing the variable by specifying the address location.

Any help would be greatly appreciated. Thanks.

0 Kudos
Reply
1 Solution
2,149 Views
ErichStyger
Specialist I

Something like this, assuming you want a 32bit read/write:

#define MY_ADDRESS (0x12345678) /* address of object *(

/* read */
int32_t i = *((int32_t*)MY_ADDRESS);

/* write */
*((int32_t*)MY_ADDRESS) = i;

There are of course many other ways you could do this in C/C++, e.g. do all the casting in the macro.

I hope this helps,

Erich

View solution in original post

3 Replies
2,128 Views
converse
Senior Contributor V

[duplicate, removed]

0 Kudos
Reply
2,127 Views
converse
Senior Contributor V

It is difficult to know the problem without seeing your code, but I guess it because you have not defined your variable as volatile.

for more information, see https://www.embedded.com/introduction-to-the-volatile-keyword/

 

0 Kudos
Reply
2,150 Views
ErichStyger
Specialist I

Something like this, assuming you want a 32bit read/write:

#define MY_ADDRESS (0x12345678) /* address of object *(

/* read */
int32_t i = *((int32_t*)MY_ADDRESS);

/* write */
*((int32_t*)MY_ADDRESS) = i;

There are of course many other ways you could do this in C/C++, e.g. do all the casting in the macro.

I hope this helps,

Erich