This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Modifying a specific bit in a register

Hello Everyone.

It is so great to be with all MCU lovers at the same place ..

I have just migrated from PIC mcus to STMs and I am quite excited with all these new stuff coming up every day , and everysecond I discover its new features ..

I got one of those minimal system boards which is coming with STM32F103C8T MCUs and I was just trying to understand Keil and its access syntax to the MCU and its registers ...

Here is my question ;

Is there a very fast way of modifying a single bit without changing the others ?
For example I know I can reach Timer2 with (TIM2->CR1)... But I don't how I can reach or change Timer2->CR1->CEN = false or true ...

Please give me a clue about that ..

Regards ..

Parents
  • You could use bit-banding, this distorts the addressing to give the appearance of bit level access.

    At the end of the day, it's a RISC processor with a load / store methodology, so doing an &= or |= operation of a bit mask against a register is pretty efficient. Bit banding can hide this a little, but it's not atomic, and it works on a 32-bit RMW, but not a big winner.

Reply
  • You could use bit-banding, this distorts the addressing to give the appearance of bit level access.

    At the end of the day, it's a RISC processor with a load / store methodology, so doing an &= or |= operation of a bit mask against a register is pretty efficient. Bit banding can hide this a little, but it's not atomic, and it works on a 32-bit RMW, but not a big winner.

Children