2024-06-24 04:56 AM - edited 2024-06-24 04:57 AM
Hello,
When I try to read USART status register (RXNE bit), the execution stucks upon while loop which means no data have been readen:
char uart2_read(void)
{
while(!(USART2->ISR & USART_ISR_RXNE)){}
return USART2->RDR;
}
I think I initialized everying neccessary to receive (and transmit) data:
void uart2_rxtx_init(void)
{
RCC->AHBENR |= RCC_GPIOA_ENABLE_FLAG;
RCC->APB1ENR = RCC_USART2_ENABLE_FLAG;
//PA2 ALTERNATIVE FUNCTION SET
GPIOA->MODER &= ~(1U << 4);
GPIOA->MODER |= (1U << 5);
//AF7
GPIOA->AFR[0] |= (1U << 8);
GPIOA->AFR[0] |= (1U << 9);
GPIOA->AFR[0] |= (1U << 10);
GPIOA->AFR[0] &= ~(1U << 11);
//PA3 ALTERNATIVE FUNCTION SET
GPIOA->MODER &= ~(1U << 6);
GPIOA->MODER |= (1U << 7);
//AF7
GPIOA->AFR[0] |= (1U << 12);
GPIOA->AFR[0] |= (1U << 13);
GPIOA->AFR[0] |= (1U << 14);
GPIOA->AFR[0] &= ~(1U << 15);
USART2->BRR = (uint16_t)(HSI_FREQ_HZ / UART_BAUDRATE);
USART2->CR1 = (CR1_TE | CR1_RE);
USART2->CR1 |= (1U << 0);
}
I use realterm terminal for the communication. Can someone explain why it doen't work?
2024-06-26 03:01 AM
Hello @a1rWAXTA ,
Please make sure to include the following settings in your Init function: