请问有没有人用过STM32F030C8T6的串口?

2019-08-08 13:22发布

我写了个程序测试STM32F030的串口,但是用串口调试助手看不到发送过来的数据。用示波器测TX引脚也没波形,请问有谁知道这是什么原因吗?谢谢!

[mw_shl_code=c,true]/** ****************************************************************************** * @file Project/STM32F0xx_StdPeriph_Templates/main.c * @author MCD Application Team * @version V1.5.0 * @date 05-December-2014 * @brief Main program body ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2> * * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * You may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.st.com/software_license_agreement_liberty_v2 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F0xx_StdPeriph_Templates * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** * @brief GPIO Config program. * @param None * @retval None */ void GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; //开启PA、PB时钟 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB,ENABLE); //串口收发引脚配置 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); //RS485控制引脚配置 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIO_InitStructure); //RS485发送 GPIO_SetBits(GPIOB,GPIO_Pin_12); // //RS485接收 // GPIO_ResetBits(GPIOB,GPIO_Pin_12); //RS485指示灯引脚配置 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11|GPIO_Pin_12; GPIO_Init(GPIOA,&GPIO_InitStructure); //点亮RS485通信标志灯 GPIO_SetBits(GPIOA,GPIO_Pin_11|GPIO_Pin_12); } /** * @brief Simple Delay program. * @param None * @retval None */ void Delay(__IO uint32_t count) { for(;count>0;count--); } /** * @brief USART1 Config program. * @param None * @retval None */ void USART1_Config(void) { USART_InitTypeDef USART_InitStructure; //打开USART1时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); //PA.2和PA3复用为USART1的收发引脚 GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_1); GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_1); //IO配置 GPIO_Config(); //串口参数初始化 USART_InitStructure.USART_BaudRate=9600; USART_InitStructure.USART_WordLength=USART_WordLength_8b; USART_InitStructure.USART_StopBits=USART_StopBits_1; USART_InitStructure.USART_Parity=USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx; USART_Init(USART1,&USART_InitStructure); //开启串口 USART_Cmd(USART1,ENABLE); } /** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Add your application code here */ USART1_Config(); /* Infinite loop */ while (1) { //发送数据 USART_SendData(USART1,0x30); //等待发送完成 while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET); //闪烁RS485通信标志灯 GPIO_SetBits(GPIOA,GPIO_Pin_11|GPIO_Pin_12); Delay(0x9ffff); GPIO_ResetBits(GPIOA,GPIO_Pin_11|GPIO_Pin_12); Delay(0x9ffff); } } /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ [/mw_shl_code]


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。