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 ..
Can you please give me an example with the syntax ? For example how to set this CEN bit of the CR1 register alone ?
#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;
Is it also ok using ;
TIM2->CR1 = TIM_CR1_CEN; // To set the bit TIM2->CR1 = !TIM_CR1_CEN; // To clear the bit
Thanks in advance(and apologies for asking possibly simple for you but difficult questions for me)
No, that's not going to work, it writes the entire register. Use the RMW form as directed.
Try reading the Cortex-M3 manual and understand Bit-banding