I still have some issues with my c code that deals with an memory mapped device. At the moment I declare the address space for the registers I write as volatile pointer and I wr
There are quite a few problems with your code:
void
where you wrote function
.volatile
as well.*
should be inside the function, not at the call site (*write_REG
) as it is now - that would be a compile error.int
which could be, say, 4 bytes away, but adding it to the address will only add 1 byte.Your corrected function should look like this:
void write_REG(unsigned int address, int offset, int data)
{
*((volatile unsigned int*)address + offset) = data;
}
and you would call it like:
write_REG(0x40000000, 0, 0x01234567);
That would be just fine IMHO. I sometimes use macros like:
#define WR_REG *(volatile unsigned int*)0x40000000
This allows the registers to be used sort of like variables:
WR_REG = 0x12345678;