Uuart series communication

4

I have a problem receiving and sending via a serial port. The communication is made from PC to STM32 micro.
From the PC I send a 0x80 and in the micro I receive 0x01, I send it a 0x81 and I receive 0xBF. If the communication is, on the contrary, from the micro I send it a 0x80 and I receive a 0x01, I send it a 0x81 and I receive 0xBF. As it is observed, the communication is coherent, with respect to the fact that the error occurs both in the sending and in the reception. This is part of the code:

char in[8];
memset(in,NULL,sizeof(in));
HAL_UART_Receive(&huart1, (uint8_t *)in, 1, 100);
HAL_UART_Transmit(&huart2, (uint8_t*) in, 1, 1); //lo mando a display
in[0]=0x81;
HAL_UART_Transmit(&huart1, (uint8_t*) in,1, 1);  //retorno a PC
HAL_Delay(200);

Configuration of the communication port with PC:

 /* USART1 init function */
    static void MX_USART1_UART_Init(void) 
   {
    huart1.Instance = USART1;
    huart1.Init.BaudRate = 19200;
    huart1.Init.WordLength = UART_WORDLENGTH_8B;
    huart1.Init.StopBits = UART_STOPBITS_1;
    huart1.Init.Parity = UART_PARITY_NONE;
    huart1.Init.Mode = UART_MODE_TX_RX;
    huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
    huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart1) != HAL_OK)
   {
   _Error_Handler(__FILE__, __LINE__);
  }
}

The configuration of the serial port (com8) is the same, 19200 baud, 8 bits without parity.

    
asked by Quarkbite 17.10.2018 в 13:38
source

0 answers