We use NXP LPC2468 Microcontroller in our target board.
We use Keil tools to build and debug our embedded C++ application.
#define UART1_BASE_ADDR 0xE0010000 #define U1RBR (*(volatile unsigned long *)(UART1_BASE_ADDR + 0x00))
What is contents of U1RBR ?
Is it address 0xE0010000 ?
or
Is it the value stored at address 0xE0010000.
Thank you!
Then that should REALLY scare you, because you really should understand this.
It's not a processor register, it's a peripheral register whose content can change from external events unrelated to the flow of program code, each time you read it the content can be different. It's exactly the case for the use of volatile. You might need to review some C language documentation to understand why that's critical.
I'm bit confused! In an earlier message of this thread, you say the following:
"it is also not volatile"
In the latest message of this thread, you say the following: "It's exactly the case for the use of volatile"
Should it be volatile or it should not be volatile?
ANY SFR that is read should be declared volatile
Erik
For simplicity that can be a sensible rule, but technically it is not always necessary.
It really depends upon the purpose of what information the SFR contains and what might actually modify the value. For example, some SFRs can be used to specify the communication speed of a serial port. The underlying hardware does not change these values in the background and therefore they do not have to be declared volatile.
Of course, something like a timer might well be changed by the underlying background (assuming that timer is enabled and active) and should be declared volatile.
You were casting it to a non-volatile type receiveRegister = (uint32 *)(&U1RBR);
"ANY SFR that is read should be declared volatile"
I may have oversimplified just a tad, however none you mention are read
For example, some SFRs can be used to specify the communication speed of a serial port. The underlying hardware does not change these values in the background and therefore they do not have to be declared volatile.
You were casting it to a non-volatile type
OK.