2019-12-19 07:58 AM
Good evening everyone,
At the moment I am trying to configure an inpute compare pin. Eventually we are going to calculate the frequency of the input signal etc etc, but for now we need to get the pin working.
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER15) |(0b10 << GPIO_MODER_MODER15_Pos);
GPIOA->PUPDR = (GPIOA->PUPDR &~GPIO_PUPDR_PUPDR15) | (0b10 << GPIO_PUPDR_PUPDR15_Pos);
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
TIM2->PSC = 0.098;
TIM2->ARR = 65535;
TIM2->CCER &= ~TIM_CCER_CC1E;
TIM2->CCMR1 |= TIM_CCMR1_CC1S_0;
TIM2->CCER |= TIM_CCER_CC1P_Msk;
TIM2->CCMR1 |= TIM_CCMR1_IC1PSC;
TIM2->CCER |= TIM_CCER_CC1E;
TIM2->DIER |= TIM_DIER_UIE;
TIM2->DIER |= TIM_DIER_CC1IE;
TIM2->CR1 |= TIM_CR1_CEN;
NVIC_EnableIRQ(TIM2_IRQn);
void TIM2_IRQHandler(void)
{
char *msgStart = "Rising edge\r\n";
HAL_UART_Transmit(&huart2, (uint8_t*)msgStart, strlen(msgStart), HAL_MAX_DELAY);
TIM2->SR &= ~TIM_SR_CC1IF;
}
Where the prescaled timer runs at 1kHz so that we can measure in ms.
So at the moment I have configured an input pin to alternate mode, set the input compare settings and made the interrupt handler.
This doesn't work when put a signal on pin PA15.
What am I doing wrong?
Solved! Go to Solution.
2019-12-19 01:57 PM
When in doubt, read out and check the registers' content; observe registers in debugger, also check if you can see changes on the input pin in the respective GPIO_IDR pin, if you see the timer running, and if you can see the timer status flags changing accordingly.
JW
2019-12-19 01:57 PM
When in doubt, read out and check the registers' content; observe registers in debugger, also check if you can see changes on the input pin in the respective GPIO_IDR pin, if you see the timer running, and if you can see the timer status flags changing accordingly.
JW
2019-12-20 02:29 AM
Thanks for your reply! We are using the Nucleo F303RE.
We didn't so we added it, still not working
We indeed didn't and we added it, still not working
It's because we want the prescaled clock to 1000Hz
No, we want to count the rising edges, all of them
We do actually, it's the function I posted;
void TIM2_IRQHandler(void)
{
char *msgStart = "Rising edge\r\n";
HAL_UART_Transmit(&huart2, (uint8_t*)msgStart, strlen(msgStart), HAL_MAX_DELAY);
TIM2->SR &= ~TIM_SR_CC1IF;
}
We are out of options, you know what's wrong?
2019-12-20 03:36 AM
As I've said above:
When in doubt, read out and check the registers' content; observe registers in debugger, also check if you can see changes on the input pin in the respective GPIO_IDR pin, if you see the timer running, and if you can see the timer status flags changing accordingly.
JW