This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Setting contents of a memory register equal to a variable

Other Parts Discussed in Thread: MSP430F2619

Rather simple question; when I run my ADC conversion adn get the value stored in ADC12MEM0 (i am using the 12bit ADC on MSP430F2619) how do i go about setting the value of this rregister equal to a variable (in C). I need to work on the value before i send it to the LCD subroutine but I need to be able to access the data first.

  • From the C point of view, the ADC register (and register) is a "volatile unsigned int" variable with the name ADC12MEM0.

    Some special mechanisms outside the C language tell the linker that this variable is physically located at the location of the hardware register. But for the compiler, it is just a normal global variable like all others. Almost:
    The 'volatile' modifier tells the compiler that any read or write to this variable shall be made immediately by accessing its memory location (so it is not cached in a CPU register or optimized otherwise, such as omitting subsequent reads or writes). This is not only important for hardware registers (where the compiler does not know that they can change value outside the program flow) but also for global variables which are modified by an interrupt routine (whcih also happens outside the normal program flow)

    You can use the name ADC12MEM0 as if it were a normal variable. So you can simply do

    unsigned int value = ADC12MEM0;

    and the code will copy the content from one ADC12MEM0 to value and you can work with it.

    Just to make it clear: All hardware registers are 'normal' (from the compilers view) memory locations and can be accessed like normal RAM. Processor registers, however, cannot be accessed with standard C (nor should one do this). An exception is the status register, for which all MSP compilers offer some ways to e.g. set the GIE bit or the LPM bits, by providing some pseudo-functions (intrinsics).

**Attention** This is a public forum