embeded/Cortex-M3 STM

stm32 uart echo

구차니 2021. 2. 4. 13:43

해당예제를 조금 더 수정하면

UART1 에서 UART2로 서로 연결할 수 있겠네?

[링크 : https://riptutorial.com/stm32/example/29940/echo-application---hal-library]

 

 

UART1은 115200 UART2는 9600인데 크게 문제 없이 잘 되는 듯?

char byte;
char byte3;
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
  if (huart->Instance == USART1)
  {
    /* Transmit one byte with 100 ms timeout */
    HAL_UART_Transmit(&huart3, &byte, 1, 100);

    /* Receive one byte in interrupt mode */
    HAL_UART_Receive_IT(&huart1, &byte, 1);
  }

  if (huart->Instance == USART3)
  {
    /* Transmit one byte with 100 ms timeout */
    HAL_UART_Transmit(&huart1, &byte3, 1, 100);

    /* Receive one byte in interrupt mode */
    HAL_UART_Receive_IT(&huart3, &byte3, 1);
  }
}


int main(void)
{
  HAL_UART_Receive_IT(&huart1, &byte, 1);
  HAL_UART_Receive_IT(&huart3, &byte3, 1);

  while (1)
  {

  }
}