小学生
最后登录1970-1-1
在线时间 小时
注册时间2020-8-9
|
我写的这个程序发送字符串,使用单板为指南者,但是串口调试助手没有显示字符串,麻烦哪位大佬帮忙看一下,谢谢!
代码如下:
#include "stm32f10x.h"
#include "bsp_led.h"
#include "bsp_key.h"
#include "stm32f10x.h" // Device header
#include "./USART/bsp_usart.h"
#define PBout(n) *(unsigned int*)(((GPIOB_BASE+0x0C)&0xF0000000)+0x02000000+(((GPIOB_BASE+0x0C)&0x00FFFFFF)<<5)+((n)<<2))
#define PAin(n) *(unsigned int*)(((GPIOA_BASE+0x08)&0xF0000000)+0x02000000+(((GPIOA_BASE+0x08)&0x00FFFFFF)<<5)+((n)<<2))
int main()
{
DEBUG_UART_Config();
//USART_SendData(DEBUG_USARTx, 'K');
Usart_SendString(DEBUG_USARTx,"我爱你中国");
while(USART_GetFlagStatus(DEBUG_USARTx, USART_FLAG_TXE == RESET));
}
#include "bsp_usart.h"
void DEBUG_UART_Config()
{
GPIO_InitTypeDef GPIO_InitStructure; /*11111*/
USART_InitTypeDef USART_InitStructure;
//第一步 初始化GPIO
RCC_APB2PeriphClockCmd(DEBUG_USART_GPIO_CLK,ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = DEBUG_USART_TX_GPIO_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = DEBUG_USART_RX_GPIO_PIN;
GPIO_Init(DEBUG_USART_RX_GPIO_PORT, &GPIO_InitStructure);
//第二步 配置串口的初始化结构体
RCC_APB2PeriphClockCmd(DEBUG_USART_CLK,ENABLE);
USART_InitStructure.USART_BaudRate = DEBUG_USART_BAUDRATE;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_Init(DEBUG_USARTx, &USART_InitStructure);
//第三步 使能串口
USART_Cmd(DEBUG_USARTx, ENABLE);
}
void Usart_SendByte(USART_TypeDef* pUSARTx, uint8_t ch)
{
USART_SendData(pUSARTx,ch);
while(USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE == RESET));
}
void Usart_SendString(USART_TypeDef* pUSARTx, char *str)
{
unsigned int k = 0;
do
{
Usart_SendByte(pUSARTx,*(str+k));
k++;
}while(*(str + k)!='\0');
while(USART_GetFlagStatus(pUSARTx, USART_FLAG_TC == RESET));
}
#ifndef _BSP_USART_H
#define _BSP_USART_H
#include "stm32f10x.h"
#define DEBUG_USARTx USART1
#define DEBUG_USART_CLK RCC_APB2Periph_USART1
#define DEBUG_USART_APBxClkCmd RCC_APB2PeriphClockCmd
#define DEBUG_USART_BAUDRATE 115200
#define DEBUG_USART_GPIO_CLK (RCC_APB2Periph_GPIOA)
#define DEBUG_USART_GPIO_APBxClkCmd (RCC_APB2Periph_GPIOA)
#define DEBUG_USART_TX_GPIO_PORT GPIOA
#define DEBUG_USART_TX_GPIO_PIN GPIO_Pin_9
#define DEBUG_USART_RX_GPIO_PORT GPIOA
#define DEBUG_USART_RX_GPIO_PIN GPIO_Pin_10
#define DEBUG_USART_IRQ USART_IRQn
#define DEBUG_USART_IRQHandler USART_IRHandler
void DEBUG_UART_Config(void);
void Usart_SendString(USART_TypeDef* pUSARTx, char *str);
#endif /*BSP_USART_H*/
|
|