AnsweredAssumed Answered

Registers issues (volatile, bit-access and bit-field)

Question asked by ashraf.salahuddin on Apr 28, 2014
Latest reply on Apr 28, 2014 by Clive One
Hi everyone,
I'm trying to understand how registers and memory really works in a microcontroller and how to access data in registers using C

Now I can access any address in the memory and I can write any data to it
Now can I access a single bit in the memory without ORing or ANDing the register's value with some other value
I watched a video on youtube that explains how to do so in TI kit and it says that there's a register called GPIO_PORTF_DATA_BITS_R which access each single bit in the memory and it says also  that the CPU can access each bit with a single data bus and a single address bus .. so that I can modify a single bit's value without using AND or OR and without any side effects on the other bits in the same register .. is this true .. and if so how can I do this with stm32f4-discovery kit

another point .. I know that there's some thing that's called bit-field and it can be used in a structure to reduce the space in memory it uses .. how can this really happen
for example, in this code
<b>
struct example2 
{ 
    int isMemoryAllocated : 1; 
    int isObjectAllocated : 1; 
}; 
 
int main(void) 
{ 
    struct example2 obj; 
 
    obj.isMemoryAllocated = 1; 
 
   return 0;
}
</b>
how can this really happen in hardware and why don't I use char data type which  is 1 byte instead of using bit-fields??

the last point which is not clear for me is the use of volatile
I know that volatile key word when used with a variable it tells the compiler that this variable can change without the control of the code in an unexpected way .. how can this happen ..
I read that this could happen in three cases including
-Interrupt handler and -memory-mapped registers ... HOW?
I hope someone to explain this in a very simple way cause I've read so much about it but I don't really understand it clearly

sorry for bothering but I'm really trying to deeply understand this stuff ..
thanks a lot

Outcomes