我可以通过kermit,putty和python串口连接到/dev/ttyACM 0,但无法在终端上显示消息。我正在使用stm32 f091 rc nucleo板构建一个项目。
Connecting to /dev/ttyACM0, speed 38400
Escape character: Ctrl-\ (ASCII 28, FS): enabled
Type the escape character followed by C to get back,
or followed by ? to see other options
我可以看到该端口显示在/dev文件夹中,但我不确定我是否真的连接到该端口。
static void MX_USART2_UART_Init(void)
{
UART_HandleTypeDef huart2;
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 38400;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
huart2.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED;
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
HAL_UART_Init(&huart2);
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
UART init函数参数与我通过Putty和Kermit进行的配置相匹配。
关于程序,我有一个主函数调用UART_Transmit函数,代码如下。
void printWelcomeMessage(void) {
HAL_UART_Transmit(&huart2, (uint8_t*)WELCOME_MSG, strlen(WELCOME_MSG), HAL_MAX_DELAY);
HAL_UART_Transmit(&huart2, (uint8_t*)MAIN_MENU, strlen(MAIN_MENU), HAL_MAX_DELAY);
}
1条答案
按热度按时间ubby3x7f1#
删除UART_HandleTypedef结构初始化行后,我已经解决了这个问题。