STM32F107VC 串口调试失败,求帮帮看看是不是程序的问题

2019-07-14 19:42发布

程序如下,作用是通过重映射USART3到GPIO10,10管脚,实现串口输出:编译通过,但是,程序数据从串口出不来,用丁丁sscom33串口调试助手一打开就显示:串口被占用或者其他错误,
#include "STM32f10x.h"
#include <stdio.h>
void RCC_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);
void delay(__IO uint32_t nCount)
{
  for (; nCount != 0; nCount--);
}
/* Private functions ---------------------------------------------------------*/
/**
  * @brief  Main program.
  * @param  None
  * @retval None
------------------------------------------------------------------------------*/
int main(void)
{
u8 i;
u8 t[]={"I LOVE XIAO"};
RCC_Configuration();
USART_Configuration();
GPIO_Configuration();
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);
for(i=0;i<8;i++)
{
  USART_SendData(USART3,t[i]);
  delay(800000);
}
}
void RCC_Configuration(void)
{

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);  
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
}
void USART_Configuration()
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_Init(USART3,&USART_InitStructure);
USART_Cmd(USART3,ENABLE);
}
void GPIO_Configuration()
{
GPIO_InitTypeDef GPIO_InitStructure;
/*Configure GPIOC.10 as USART3_Tx*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
/*Configure GPIOC.11 as USART3_Rx*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}

0条回答

一周热门 更多>