title: STM32 uart forwarding
body: <p>I need to link two UARTs. Each byte received by one of them is sent to the other and vice-versa. Both have the same baud rate 9600 and configuration. If I send some characters to uart 1 via putty I can see that the data is available at <em><strong>byte</strong></em> but but its not send to uart 2?</p>
  <p>any feedback or suggestions are appreciated</p>
  <pre><code>void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
  {
    /* Prevent unused argument(s) compilation warning */
    UNUSED(huart);
  
    /* NOTE: This function should not be modified, when the callback is needed,
             the HAL_UART_RxHalfCpltCallback can be implemented in the user file.
     */
      
          // USART_ISR_RXNE  = Read Data Register Not Empty 
          // USART_CR1_TXEIE = TXE Interrupt Enable 
      
      
          // uart 1 
          if(huart == &amp;huart1){
              if (USART1-&gt;ISR &amp; USART_ISR_RXNE){
                      byte = USART1-&gt;RDR;
                      USART2-&gt;CR1 |= USART_CR1_TXEIE;
              }
              if ((USART1-&gt;CR1 &amp; USART_CR1_TXEIE) &amp;&amp;  (USART1-&gt;ISR &amp; USART_ISR_RXNE)){
                      USART1-&gt;CR1 &amp;= ~USART_CR1_TXEIE;
                      USART1-&gt;RDR = byte2;
              }
          }
          // uart 2 
          if(huart == &amp;huart2){
              if (USART2-&gt;ISR &amp; USART_ISR_RXNE){
                      byte2 = USART2-&gt;RDR;
                      USART1-&gt;CR1 |= USART_CR1_TXEIE;
              }
              if ((USART2-&gt;CR1 &amp; USART_CR1_TXEIE) &amp;&amp;  (USART1-&gt;ISR &amp; USART_ISR_RXNE)){
                      USART2-&gt;CR1 &amp;= ~USART_CR1_TXEIE;
                      USART2-&gt;RDR = byte;
              }
          }
  
  }
  </code></pre>
  <p>I think I have it working outside the transfer callbacks now. but still very much interested in old attempted</p>
  <pre><code>volatile uint8_t byte = '\0';
  volatile uint8_t byte2 = '\0';
  
  
  int main(void)
  {
  
    HAL_Init();
    SystemClock_Config();
      
    MX_GPIO_Init();
    MX_USART1_UART_Init();
    MX_USART2_UART_Init();
          
      
    while (1)
    {
                  if (USART1-&gt;ISR &amp; USART_ISR_RXNE){
                      while (!(USART1-&gt;ISR &amp; USART_ISR_RXNE) ){
                      __NOP();
                      };
                      byte = USART1-&gt;RDR;
  
                      USART2-&gt;TDR = byte;
                      while (!(USART2-&gt;ISR &amp; USART_ISR_TXE)){
                      __NOP();
                      };  
                  }
                      
                  if (USART2-&gt;ISR &amp; USART_ISR_RXNE){
                      while (!(USART2-&gt;ISR &amp; USART_ISR_RXNE) ){
                      __NOP();
                      };
                      byte2 = USART2-&gt;RDR;
  
                      USART1-&gt;TDR = byte2;
                      while (!(USART1-&gt;ISR &amp; USART_ISR_TXE)){
                      __NOP();
                      };
              }
    }
      
  }
  </code></pre>