I am reading a register map for a UART and the base memory mapped address for the UART is 0x00021000. I've created a pointer to this address as:
#define UART_BASE 0x00021000
volatile uint32_t *uart = (volatile uint32_t*) UART_BASE;
The register map is attached and the status register is offset by 2. What would be the address of the status register?
#define UART_STATUS 0x00021000
volatile uint32_t *uart = (volatile uint32_t*) UART_STATUS
This for an arduino project that I'm porting to another (more difficult) MCU.
Thanks
system
March 10, 2017, 2:23pm
2
What would be the address of the status map?
I do not know what you mean by "status map". There is a status register, at UART_BASE+2.
sorry that was a typo fixed now.
uint32_t is 32 bits, so wouldn't it just be uart+1? (that is incrementing the base by 32 bits, 16 bits for rx, 16 bits for tx).
Hi tammytam,
Thanks, but if UART base is at 0x00021000 how can you calculate the address of the status register only? I suppose that is my question, sorry. It is 0x00021000 + ? = status register address.
Thanks
0x00021004
That is if you are addressing bytes. Or do it from the base pointer like I put:
volatile uint32_t *uart = (volatile uint32_t*) UART_BASE;
volatile uint32_t *status = uart+1;
I think
sorry if this is a really stupid question but how did you calculate 0x00021004?
4 bytes offset from the base, 2 bytes (16 bit) for the RX, 2 bytes (16 bit) for the TX. Should place you at the start of the status register.
system
March 10, 2017, 11:34pm
10
Why are you using a 32 bit pointer to point to 16 bit data? Life would be so much simpler if you used a pointer that was the same size as the data you are pointing to.
Then, the offset would be 2.