Skip to main content
Ahajr.1
Associate II
June 17, 2021
Question

Failed to communicate with device using Nucleo uart

  • June 17, 2021
  • 1 reply
  • 720 views

Hello,

I'm using nucleo board f410rb to communicate with another device via UART, my Baudrate is correctly fixed , i checked with the builder of the device the command i should send , i wrote the following code but the device dosen't respond

uint8_t tx_buff[]={0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xAA, 0x55, 0x00, 0x00, 0x70, 0x37};

int main(void)

{

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* Configure the system clock */

 SystemClock_Config();

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_USART1_UART_Init();

 MX_USART2_UART_Init();

 /* USER CODE BEGIN WHILE */

 HAL_UART_Transmit(&huart2, (uint8_t *)com_buff,sizeof(com_buff), HAL_MAX_DELAY);

 HAL_UART_Transmit(&huart2, (uint8_t *)msg_screen,sizeof(msg_screen), HAL_MAX_DELAY);

 while (1)

 {

  /* USER CODE END WHILE */

 UartStatus = HAL_UART_Transmit(&huart1, (uint8_t *)tx_buff,sizeof(tx_buff), HAL_MAX_DELAY);

 if (UartStatus != HAL_OK) {

 HAL_Delay(10000);

 }

HAL_Delay(10);

  /* USER CODE BEGIN 3 */

 }

I'm starting to have doubts on how uart transmit buffer works but i don't know where is my mistake

Thank you in advance

This topic has been closed for replies.

1 reply

Ahajr.1
Ahajr.1Author
Associate II
June 18, 2021

This issue was solved by changing some byte on buffer command.

Now i'm able to see my device responding using scope.

Using HAL_UART_Receive the read buffer is always empty and the function stuck on :

if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)

   {

    return HAL_TIMEOUT;

   }

Does any one have an idea about that?