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
  • #include <stm32f10x.h> // For SPL 3.5.0
    
    #define TIM2_OFFSET             (TIM2_BASE - PERIPH_BASE)
    
    /* Alias word address of CEN bit */
    #define TIM2CR1_OFFSET          (TIM2_OFFSET + 0x00)
    #define CEN_BitNumber           0x00 // TIM_CR1_CEN = 0x0001
    #define CR_TIM2CEN_BB           (PERIPH_BB_BASE + (TIM2CR1_OFFSET * 32) + (CEN_BitNumber * 4))
    
    
    // Bit Banded
    
    *((uin32_t *)CR_TIM2CEN_BB) = 1;
    *((uin32_t *)CR_TIM2CEN_BB) = 0;
    
    
    // Regular
    
    TIM2->CR1 |= TIM_CR1_CEN;
    TIM2->CR1 &= ~TIM_CR1_CEN;
    

Reply
  • #include <stm32f10x.h> // For SPL 3.5.0
    
    #define TIM2_OFFSET             (TIM2_BASE - PERIPH_BASE)
    
    /* Alias word address of CEN bit */
    #define TIM2CR1_OFFSET          (TIM2_OFFSET + 0x00)
    #define CEN_BitNumber           0x00 // TIM_CR1_CEN = 0x0001
    #define CR_TIM2CEN_BB           (PERIPH_BB_BASE + (TIM2CR1_OFFSET * 32) + (CEN_BitNumber * 4))
    
    
    // Bit Banded
    
    *((uin32_t *)CR_TIM2CEN_BB) = 1;
    *((uin32_t *)CR_TIM2CEN_BB) = 0;
    
    
    // Regular
    
    TIM2->CR1 |= TIM_CR1_CEN;
    TIM2->CR1 &= ~TIM_CR1_CEN;
    

Children