Hello guys
I coded a function that receives over UART, and it's working fine using polling. Now, I want to make it using interrupts, I'm not being able to receive anything. With Stm32, I played a lot using external interrupt, but never another type of interrupts, so I'm a bit stuck. I know with external interrupt, you have to clear them in the IRQ handler, but I didn't find a way to do it with Uart. I hope I'm not doing something stupid here! Can someone tell me what I'm doing wrong, please?TIA
This is my code:
void usart_init(void)
{
/* alternate function 7
usart6_TX PA11
usart6_RX PA12 */
static uint16_t usart_tx=PIN('A',11);
static uint16_t usart_rx=PIN('A',12);
gpio_init(usart_rx, GPIO_MODE_AF, GPIO_OTYPE_PUSH_PULL, GPIO_SPEED_INSANE,GPIO_PULL_NONE, 8);
gpio_init(usart_tx, GPIO_MODE_AF, GPIO_OTYPE_PUSH_PULL, GPIO_SPEED_INSANE,GPIO_PULL_NONE, 8);
RCC->APB2ENR |=RCC_APB2ENR_USART6EN ;//enable usart6 clock
/*oversamling 16
div=84MHZ/9600=8750=0x222e */
USART6->BRR =0x222e;
USART6->CR1 |=USART_CR1_RE | USART_CR1_TE |USART_CR1_RXNEIE ;//enable receiver , transmitter and interrupt enabled
NVIC_EnableIRQ(USART6_IRQn);
USART6->CR1 |=USART_CR1_UE; //enable usart
the IRQ handler:
void USART6_IRQHandler (void)
{
if(USART6->SR & USART_SR_RXNE)
usart_itp=1;
}
the receiving function
uint8_t usart_receive_char(void)
{
if(usart_itp)
usart_itp=0;
return USART6->DR;
}