2016-04-07 06:11 AM
Hi,
I use 2 UART ports: UART1 for WiFi and UART4 for debug output. My goal is to send to UART4 data I received on UART1. When I use only 1 UART, it works (UART4), everything I typed on keyboard, returned back. I implemented next: char RX1[2], RX4[2]; SerialCrtl com4_ctrl, com1_ctrl; // structure for data buffer void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) /// callback function for UART, adding received data into buffer { if (huart->Instance == UART4) { com4_ctrl.recv_buffer[com4_ctrl.recv_buffer_end++] = RX4[0]; HAL_UART_Receive_IT(&huart4, RX4, 1); //activate UART receive interrupt every time } else if (huart->Instance == USART1) { com1_ctrl.recv_buffer[com1_ctrl.recv_buffer_end++] = RX1[0]; HAL_UART_Receive_IT(&huart1, RX1, 1); //activate UART receive interrupt every time } } and function for FreeRTOS (this works when I use only UART4): void readCom(void const *pvParameters) { com1_ctrl.recv_buffer_end = 0; memset(com1_ctrl.recv_buffer, 0, sizeof(com1_ctrl.recv_buffer)); while(1) { if (com1_ctrl.recv_buffer_end > 0) { //strcpy(com4_ctrl.send_buffer, com4_ctrl.recv_buffer); sprintf(com4_ctrl.send_buffer, ''OUT> [%s] [%d]\r\n'', com4_ctrl.recv_buffer, com1_ctrl.recv_buffer_end); com4_ctrl.send_buffer_length = strlen(com4_ctrl.send_buffer); //HAL_UART_Transmit(&huart4, com4_ctrl.send_buffer, com4_ctrl.send_buffer_length, 1000); HAL_UART_Transmit(&huart4, com1_ctrl.recv_buffer, com4_ctrl.recv_buffer_end, 1000); HAL_Delay(100); memset(com4_ctrl.send_buffer, 0, sizeof(com4_ctrl.send_buffer)); memset(com1_ctrl.recv_buffer, 0, sizeof(com1_ctrl.recv_buffer)); com4_ctrl.send_buffer_length = com1_ctrl.recv_buffer_end = com1_ctrl.recv_buffer_start = 0; } HAL_Delay(2000); HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_14); } } in main() I added these 2 lines for activation of interupt for UART: HAL_UART_Receive_IT(&huart4, RX4, 1); HAL_UART_Receive_IT(&huart1, RX1, 1); I also tried without callback function, I added in thread function what only reads UARTs, but it works also only with one active UART. Any idea what's wrong here? Cheers #freertos #hal #uart