Keil- ARM compiler Write and read from absolute address

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Keil- ARM compiler Write and read from absolute address

ソリューションへジャンプ
1,755件の閲覧回数
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 件の賞賛
1 解決策
1,751件の閲覧回数
ErichStyger
Senior Contributor V

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

元の投稿で解決策を見る

3 返答(返信)
1,730件の閲覧回数
converse
Senior Contributor V

[duplicate, removed]

0 件の賞賛
1,729件の閲覧回数
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 件の賞賛
1,752件の閲覧回数
ErichStyger
Senior Contributor V

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