STM32F303k8 UART receive data read loop issue
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2024-06-24 4:56 AM - edited 2024-06-24 4: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?
Labels:
- Labels:
-
STM32F3 Series
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2024-06-26 3:01 AM
Hello @a1rWAXTA ,
Please make sure to include the following settings in your Init function:
- StopBits
- WordLength
- Parity
- CLKPolarity
- CLKPhase
- CLKLastBit
To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
Saket_Om
