stm32 串口调试不通

2019-03-23 19:39发布

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include <stdio.h>

USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* Private function prototypes -----------------------------------------------*/
#ifdef __GNUC__
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
  
int main(void)
{
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  /* Configure USART Tx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  /* Configure USART Rx as input floating */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  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 configuration */
  USART_Init(USART1,&USART_InitStructure);   
  /* Enable USART */
  USART_Cmd(USART1, ENABLE);
  /* Output a message on Hyperterminal using printf function */
  printf(" USART Printf Example: retarget the C library printf function to the USART ");
  while (1)
  {
  }
}
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART */
  USART_SendData(USART1, (uint8_t) ch);
  /* Loop until the end of transmission */
  while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
  {}
  return ch;
}
#ifdef  USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
  while (1)
  {
  }
}
#endif
上面是我改的串口1的整个main程序,不知道是什么问题,下载到stm32里面就是没有反应,前提是我确定板子肯定没有问题,请大家帮帮我看看,到底是什么地方出了问题:我的芯片的型号是stm32f103ZET6,我是通过串口下载的。 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
8条回答
shaohua411
1楼-- · 2019-03-23 23:01
/ 没有人帮忙回答吗,请大家帮帮忙了,实在不知道什么地方出了问题
shirl
2楼-- · 2019-03-24 04:55
 精彩回答 2  元偷偷看……
shaohua411
3楼-- · 2019-03-24 05:53
你好,这个我不知道,不是板子不运行,而是程序的问题,麻烦你看看我的程序是不是有问题啊,这是针对3.5的库改的
Ice_08
4楼-- · 2019-03-24 10:56
你发送完数据之后是不是要对标志位进行置位啊?
就是 while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)之后,
把标志位还原。
还有就是先试试低一点的波特率,比如9600,115200的波特率太高了,有可能设备本身就接受不了这么高的传输速度。
beyond696
5楼-- · 2019-03-24 11:43
 精彩回答 2  元偷偷看……
ddllxxrr
6楼-- · 2019-03-24 15:00

一周热门 更多>