Reputation: 59
I'm trying to get the value of at an address in memory in my microcontroller. The address is at 0x1fff7000
and that's the start of the memory block (so anything before is undefined). In my code I have char *ptr = (char *)BASE_ADDR;
where #define BASE_ADDR ((uint32_t)0x1FFF7000)
. My value at 0x1FFF7000
is 0x12345678
and I know 100% that it's there.
In GDB, I'm doing (gdb) p/x *ptr
and my return value is $6 = 0x78
. Why is it at 0x78
and not returning 0x12345678
or even 0x12
?
Upvotes: 1
Views: 168
Reputation: 1641
Because you have a little-endian system/mcu, which means least significant bytes are stored first. In your example, the 0x12345678
, stored as a 32 bit integer, is going to look as 78 56 34 12
as raw data in memory.
Upvotes: 6
Reputation: 67820
define it as uint32_t *ptr = (volatile char *)BASE_ADDR;
then read.
(char *) can reference the value from -128 to 127.
Also read about the endianess. https://en.wikipedia.org/wiki/Endianness
As I wrote in your other questions - before you program uCs you need to learn some basics. Bitwise operations, endianess etc etc.
Upvotes: 3