same STM32 UART1_TX is connected to UART2_RX. But UART2_RX only receive 1st element
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2024-01-21 8:36 PM
If you have time, please help me to find the solution to enhance the code below. In same STM32F103C8T6, UART1_TX is connected to UART2_RX which is received data from TX.
#include "main.h"
#include <stdio.h>
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
...
uint8_t TxData[] = {2, 1, 3};
uint8_t RxData[5] ;
/*#################### usart1Tx = PA9 connect usart2RX = PA3 ####################*/
int main(void)
{
...
while (1)
{
HAL_UART_Transmit(&huart1, TxData, sizeof(TxData), HAL_MAX_DELAY);
HAL_UART_Receive(&huart2, RxData, sizeof(RxData), HAL_MAX_DELAY);
}
}
Labels:
- Labels:
-
STM32F1 Series
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2024-01-21 11:45 PM
The code above sends three bytes. The first byte is received by UART but not read from it, so the other bytes are lost. Then you call Receive, which reads the only byte received. So, everything works as expected. Read the description of non-blocking functions, like HAL_UART_Receive_IT(). Call it first, then call Transmit - the bytes sent will be received in the background. Or better - don't use HAL for UART - it doesn't fit any real world scenario. ;)
My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
