【3】STM32F103嵌入式编程之路:通过串口发送字符串

通过串口发送字符串

开发板上拥有2个COM口(通过跳线可设置成485或232模式),我们可以通过串口通信让开发板与PC之间产生通讯。

硬件部分

查阅手册得知,实际上RS232接口定义上只有2脚输入3脚输出是实际用到的。
在这里插入图片描述
在这里插入图片描述
通过232串口线直接连到电脑,或者USB转换头接入电脑即可。这里分享一下USB转232线的驱动包:

链接: https://pan.baidu.com/s/15O28JYnpxWOHHs6JVJPxtA 提取码: 3eus

代码部分

头文件及定义

#include "stm32f10x.h"
#include "stm32_eval.h"
#include <stdio.h>

#ifdef __GNUC__
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif 
  
#ifdef  USE_FULL_ASSERT

void assert_failed(uint8_t* file, uint32_t line)
{ 
  while (1)
  {
  }
}
#endif

USART_InitTypeDef USART_InitStructure;


PUTCHAR_PROTOTYPE
{
  USART_SendData(EVAL_COM1, (uint8_t) ch); 
  while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
  { 
  }
  return ch;
}

猜你喜欢

转载自blog.csdn.net/weixin_44234948/article/details/85257835