2016-02-01 06:20 AM
I want to generate an interrupt from software in order to execute things in a different ''thread'' than the main()-thread. In other Microcontroller-brands I've been previously working with this has been very easy to achieve, I would simply enable the interrupt and set the interrupt flag. When I try to do that with my STM32F04-microcontroller, nothing happens:
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
TIM3->DIER |= TIM_DIER_UIE; // Update interrupt enable
HAL_NVIC_EnableIRQ(TIM3_IRQn); // Enable interrupts
TIM3->SR |= TIM_SR_UIF; // Set interrupt flag
void TIM3_IRQHandler(void)
{
UART1_TransmitNullTerminatedString(''\r\nTIM3_IRQHandler''); // This is never executed. Why?
}
What is the proper way to issue arbitrary interrups (TIM3_IRQHandler, CAN1_RX0_IRQHandler, DMA2_Stream6_IRQHandler or whatever) from software?
2016-02-01 07:57 AM
perhaps read up on SETPEND and STIR.
2016-02-01 08:06 AM
Thanks for your reply. The following works fine (in this example I want to issue a
CAN1_TX_IRQHandler-interrupt):HAL_NVIC_EnableIRQ(CAN1_TX_IRQn);
NVIC->STIR = CAN1_TX_IRQn;
2016-02-02 01:57 AM
Hi arnold_w,
To generate a Timer update event (UEV)by software, you set the UG bit the TIMx_EGR register. before that,you should ensure that the URS bit is already is reset (default value)./* Reset the URS bit */
TIM1-> CR1 &= ~ TIM_CR1_URS;
/* Enable UEV by setting UG bit */
TIM1->EGR |= TIM_EGR_UG;
-Hannibal-