Keil- ARM compiler Write and read from absolute address

cancel
Showing results for 
Search instead for 
Did you mean: 

Keil- ARM compiler Write and read from absolute address

95 Views
aswinprabhu
Contributor II

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
3 Replies

70 Views
converse
Senior Contributor IV

[duplicate, removed]

0 Kudos

69 Views
converse
Senior Contributor IV

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

91 Views
ErichS
Senior Contributor II

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