How can i handle two UART ports in one STM32?
Hello,
I have questions about handling multiple UART ports.
Connections are;
PC <--USB VCP--> STM32(1) <--UART1--> STM32(2) <--UART2--> Target device
Two STM32 are both L412K series,
And I wanna make a application which forwards data to the target device which sends from PC.
I found STM32(1) works properly.
When the data is coming through USB VCP, it repeats data to STM32(2).
However, STM32(2) does not send character to UART2.
I think it receives the data through UART1, but not forwarding it to UART2.
Here is the code which I wrote for STM32(2).
uint8_t data;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
HAL_Delay(100);
MX_USART1_UART_Init();
HAL_Delay(500);
MX_USART2_UART_Init();
HAL_Delay(500);
HAL_UART_Receive_IT(&huart1, &data,1);
while (1)
{
}
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
if(huart->Instance == huart1.Instance){
HAL_UART_Transmit(&huart2, &data, 1, 10);
}
HAL_UART_Receive_IT(&huart1, &data, 1);
}(all the unnecessary codes are removed)
Is this cannot be implemented in this simple way?
Please let me know.
Thank you.