#include "usart.h" extern void Error_Handler(void); UART_HandleTypeDef huart2; UART_HandleTypeDef husart_debug; UART_HandleTypeDef UartHandle; void HAL_UART_MspInit(UART_HandleTypeDef* huart) { GPIO_InitTypeDef GPIO_InitStruct; if(huart->Instance==USART2) { /* USER CODE BEGIN USART2_MspInit 0 */ /* USER CODE END USART2_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_USART2_CLK_ENABLE(); /**USART2 GPIO Configuration PA0-CK_IN ------> USART2_RX PA9 ------> USART2_TX */ GPIO_InitStruct.Pin = GPIO_PIN_0; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF0_USART2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF0_USART2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USER CODE BEGIN USART2_MspInit 1 */ /* USER CODE END USART2_MspInit 1 */ } } void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) { if(huart->Instance==USART2) { /* USER CODE BEGIN USART2_MspDeInit 0 */ /* USER CODE END USART2_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART2_CLK_DISABLE(); /**USART2 GPIO Configuration PA0-CK_IN ------> USART2_RX PA9 ------> USART2_TX */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_9); } } void MX_USART2_UART_Init(void) { __HAL_RCC_GPIOA_CLK_ENABLE(); huart2.Instance = USART2; huart2.Init.BaudRate = 115200; 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; //HAL_UART_Init(&huart2); if (HAL_UART_Init(&UartHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } } /** * º¯Êý¹¦ÄÜ: Öض¨Ïòc¿âº¯Êýprintfµ½DEBUG_USARTx * ÊäÈë²ÎÊý: ÎÞ * ·µ »Ø Öµ: ÎÞ * ˵ Ã÷£ºÎÞ */ int fputc(int ch, FILE *f) { HAL_UART_Transmit(&husart_debug, (uint8_t *)&ch, 1, 0xffff); return ch; } /** * º¯Êý¹¦ÄÜ: Öض¨Ïòc¿âº¯Êýgetchar,scanfµ½DEBUG_USARTx * ÊäÈë²ÎÊý: ÎÞ * ·µ »Ø Öµ: ÎÞ * ˵ Ã÷£ºÎÞ */ int fgetc(FILE * f) { uint8_t ch = 0; HAL_UART_Receive(&husart_debug,&ch, 1, 0xffff); return ch; } int main(void) { /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ //MX_GPIO_Init(); //MX_ADC_Init(); MX_USART2_UART_Init(); while (1) { // I2C_Write(0x0000,1); printf("s"); HAL_Delay(500); } } 型号是STM32L011什么波形都没有,哪位大神帮忙看下谢谢! |
STM32L011D4芯片用SWD无法下载程序
求助:STM32L0系列标准库哪里下?
STM32L051低温时LPUART串口波特率异常
STM32L051单片机ADC如何彻底关闭?
STM32L051C8进入低功耗模式电流偏大
STM32L052C8T6通过I2C模拟读16位数
STM32L0的VLCD外接5V会有问题吗
求助!!使用STM32L073 IO口模拟IIC接口读写AT24CM01 程序不停...
STM32L072RB写Bank2 EEPROM不响应中断
STM32L031无法进入boot
有通信,串口线就会产生方波不是?