Receiving data from USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-04-15 1:42 AM
I am trying to use asynchronous USART on stm32L4R5ZI nucleo board for sending and receiving data. Following is related part of code.
while (1)
{
HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin); //Toggle LED
HAL_Delay(1000); //Delay 1 Seconds
for(i = 0; i < 5; i++)
{
USART1->TDR = p[i];
while((USART1->ISR & 0x40) == 0);
}
while ((USART1->ISR & 0x20) == 0);
uint32_t receivedByte = (uint32_t)(USART1->RDR);
}
Problem is that I am able to send data to PC but I am not able to receive data. What can be the problem?
- Labels:
-
STM32L4 Series
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-04-15 1:55 AM
It is not wired properly.
You are not clearing any pending noise or overflow flags, etc on the receiver.
The code might work more effectively if you don't continually block, and check for TXE before sending a byte.​
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-04-15 3:14 AM
I have checked wiring is proper.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-04-15 5:41 AM
Or test you this code:
uint8_t getChar()
{
uint8_t InputData = 0;
while (1)
{
if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_ORE))
__HAL_UART_CLEAR_OREFLAG(&huart1);
if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE))
{
InputData = huart1.Instance->RDR & 0x1FF;
return InputData;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-05-25 4:07 AM
This resolved my problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-05-25 4:33 AM
This is polling based. If you want to keep it that way, add the DMA as cyclic buffer filling from RX side, then check the incoming buffer regularly.
Transmit can be polling as you are in control of sending data timeline.
Imagine that you add a HAL_Delay(10) somewhere in your code, you might lose incoming bytes from USART the way it is here. From example to application type example.
