Communication UART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-06 2:56 AM
Good morning,
HAL_UART_Transmit(&huart2,myRxData,11,10);
HAL_UART_Receive(&huart2,myRxData,11,100);
My question is: only to make a test of sending and receiving data is enough to use the previous functions and make the connection of the pins tx with rx and rx with tx using the configuration of usart2 for the electronic card stm32f411 or should I do something more? Thank you.
- Labels:
-
STM32Cube MCU Packages
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-06 3:34 AM
hello!
You can't use these functions to make a loop-back test.
these are blocking functions that means HAL_UART_Transmit will not return until transmit all 11 bytes or timeout. So HAL_UART_Receive will called after transmit finishes.
Try the IT versions of these functions (HAL_UART_Transmit_IT with appropriate callbacks and different buffers to have both RX and TX simultaneously.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-06 8:00 AM
Reception can occur anytime, so use at least Receive using Interrupt (IT)
For transmit, you can use polling.
You'll have to learn how to react when a byte has been received, fill a buffer, decide when the message is ready for processing, and set a flag for the main loop to react.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-07 6:24 AM
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-07 6:24 AM
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-07 7:30 PM
I agree I am working with interruptions as you suggested to me using the code:
Transmitter code.
uint8_t Rx_data[]={1,2,3,4};
while (1)
{
HAL_UART_Transmit_IT(&huart2,(uint8_t *)Rx_data,4);
HAL_Delay(200);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
#####################################
Receiver code
#####################################
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
//uint8_t Rx_data[10];
uint8_t Rx_data[4];
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(&huart2,Rx_data,4);
}
/* USER CODE END 0 */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart2,Rx_data,4);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
HAL_Delay(500);
}
Then I use two different computers to load each part of the code, the transmission and reception and first execute the reception so that it is ready to receive and then the transmission code, however in the reception debbug I observe absolutely nothing.
When I run and test the transmitter code, I test it in this way.
When executing and testing the reception code, I test it in this way
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-07 7:32 PM
I agree I am working with interruptions as you suggested to me using the code:
Transmitter code.
uint8_t Rx_data[]={1,2,3,4};
while (1)
{
HAL_UART_Transmit_IT(&huart2,(uint8_t *)Rx_data,4);
HAL_Delay(200);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
#####################################
Receiver code
#####################################
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
//uint8_t Rx_data[10];
uint8_t Rx_data[4];
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(&huart2,Rx_data,4);
}
/* USER CODE END 0 */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart2,Rx_data,4);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
HAL_Delay(500);
}
Then I use two different computers to load each part of the code, the transmission and reception and first execute the reception so that it is ready to receive and then the transmission code, however in the reception debbug I observe absolutely nothing.
When I run and test the transmitter code, I test it in this way.
When executing and testing the reception code, I test it in this way
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-07 7:33 PM
I agree I am working with interruptions as you suggested to me using the code:
Transmitter code.
uint8_t Rx_data[]={1,2,3,4};
while (1)
{
HAL_UART_Transmit_IT(&huart2,(uint8_t *)Rx_data,4);
HAL_Delay(200);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
#####################################
Receiver code
#####################################
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
//uint8_t Rx_data[10];
uint8_t Rx_data[4];
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(&huart2,Rx_data,4);
}
/* USER CODE END 0 */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart2,Rx_data,4);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
HAL_Delay(500);
}
Then I use two different computers to load each part of the code, the transmission and reception and first execute the reception so that it is ready to receive and then the transmission code, however in the reception debbug I observe absolutely nothing.
When I run and test the transmitter code, I test it in this way.
When executing and testing the reception code, I test it in this way
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-08 4:12 AM
Callback is done within the interrupt! That is where you get an incoming byte and you ve got to do something quick about it. Activate the IT from the main loop, add a 100ms delay, then transmit... For test
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-03-22 2:44 AM
Hi @lmeli​
You can't use these functions to do the loop-back test.
You can Try the IT versions of this function HAL_UART_Transmit_IT with appropriate reminders and different buffers to have RX and TX simultaneously.
Best regards.
Nesrine
