16年5个月前IP:未同步
247665
9楼
请问楼主,我没有出现你写代码的错误,但是结果和你的一样,是怎么回事啊?急!!!!!!!!!!!!望尽快给答复,谢谢!

附我的代码:
#include "stm32f10x.h"

/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;

/* Private function prototypes -----------------------------------------------*/
void delay(uint32_t nCount);
void UART1_GPIO_Configuration(void);
void UART1_Configuration(void);

/**********************************主函数****************************************/
int main(void)
{
  /* Setup STM32 system (clock, PLL and Flash configuration) */
  SystemInit();

  /* GPIOx and AFIO clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
   /* USART1 clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

  UART1_GPIO_Configuration();
  UART1_Configuration();

  while(1)
  {
        GPIO_SetBits(GPIOB, GPIO_Pin_5);
        USART_SendData(USART1, (u8) 0xa4);
        while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
        delay(0xffff);
        GPIO_ResetBits(GPIOB, GPIO_Pin_5);
        delay(0xfffff);
  }

}

/*********************************配置UART的GPIO口*************************************/
void UART1_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// Configure USART1_Tx as alternate function push-pull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

// Configure USART1_Rx as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);

// Configure GPIOB
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);

}


/************************************配置串口参数***********************************/

void UART1_Configuration(void)
{

   USART_InitTypeDef USART_InitStructure;
   USART_ClockInitTypeDef USART_ClockInitStructure;


   USART_InitStructure.USART_BaudRate = 115200;
   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_ClockInitStructure.USART_Clock = USART_Clock_Disable;
   USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
   USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
   USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;

   USART_ClockInit(USART1,&USART_ClockInitStructure);

   USART_Init(USART1, &USART_InitStructure);

   USART_Cmd(USART1, ENABLE);
}

/***********************************延时子函数***********************************/

void delay(uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}
/********************************End of function def********************************/

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\\r\\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif

/**
  * @}
  */
评论
文号 / 247665

实习会员
名片发私信
学术分 0
总主题 2 帖总回复 3 楼拥有证书:笔友
注册于 2010/08/12 16:06:17最后登录 2018/01/10 01:12:37
主体类型:个人
所属领域:无
认证方式:邮箱
IP归属地:0

个人简介

暂未填写
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的