STM32F0 UART interrupt problem
Hi,
I am using STM32F051 controller. I have done UART initialization coding but I am not getting interrupt for it. Is there any problem with alternate function register configuration. I am using Pin PB6 and PB7 for Uart. Also I tried finding example code for UART interrupt but didn't code for UART (STM32F051). Kindly help.
void UART_config(void){
//-----Enable USART Clock----------------------------------------
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
// Configure PB6 (Tx) and PB7 (Rx)
GPIOB->AFR[0] |= 0x00000000; //AFRL, PB6, UART1
GPIOB->AFR[0] |= 0x00000000; //AFRL, PB7, UART1
GPIOB->MODER &= ~0x0000F000; //Clear PB6 & PB7
GPIOB->MODER |= GPIO_MODER_MODER6_1; //Alternate Fxn mode
GPIOB->MODER |= GPIO_MODER_MODER7_1; //Alternate Fxn mode
GPIOB->OTYPER &= ~GPIO_OTYPER_OT_6; //Output Push/Pull
GPIOB->OTYPER &= ~GPIO_OTYPER_OT_7; //Output Push/Pull
GPIOB->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR6_1; //PB6 high speed
GPIOB->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR7_1; //PB7 high speed
GPIOB->PUPDR |= GPIO_PUPDR_PUPDR6_0; //PB6 Pull up
GPIOB->PUPDR |= GPIO_PUPDR_PUPDR7_0; //PB7 Pull up
USART1->CR1 = 0x00000000;
USART1->BRR = (SystemCoreClock / 9600);
USART1->CR2 = 0x00000000; //To make number of stop bits 1
USART1->CR1 |=USART_CR1_TE | USART_CR1_UE | USART_CR1_RE | USART_CR1_RXNEIE | USART_CR1_TCIE;
}
void USART1_IRQHAndler(void){
if (USART1->ISR & USART_ISR_RXNE) { // read interrupt
//for read operation
}
if (USART1->ISR & USART_ISR_TXE) {
//for transmit
}
}
