通过串口发送字符串
开发板上拥有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;
}