STM32F7 Timer Event Generation Register Wrong address?
Hello I'm using a STM32F769 discovery board. I was trying to use timer2channel2 to trigger the ADC conversion. I am setting registers manually and wanted to turn on event generation on channel 2 match.
TIM2->EGR |= TIM_EGR_CC2G_Msk;
However when I ran the code it didn't work. I opened the debugger and discovered when I run that particular line of Code it is actually setting the same bit in the status register (TIm2->SR) has anyone else seen this problem? Is there any work around, or am I just missing something
heres my code for reference
void init_timer2(void)
{
//1. Clock
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN_Msk;
TIM2->PSC = 1600 -1;
TIM2->ARR = 10000;
TIM2->CNT = 0;
TIM2->CCR2 = 1000;
//now set up trigger, we are basically using compare mode
TIM2->EGR |= TIM_EGR_CC2G_Msk
| TIM_EGR_UG_Msk; //this doesn't work whenever you write to EGR it goes to SR register
TIM2->CCMR1 |= (0x01 << TIM_CCMR1_OC2M_Pos)//sets pin high on compare match
| (0x01 << TIM_CCMR1_OC2PE_Pos);//enable preload register?
TIM2->CCER |= TIM_CCER_CC2E_Msk;
//start timer
TIM2->CR1 |= TIM_CR1_CEN_Msk;
}