#include "usart.h"
#include "stdio.h"
#if 1
#pragma import(__use_no_semihosting)
//??????????
struct __FILE
{
int handle;
};
FILE __stdout;
//??_sys_exit()??????????
_sys_exit(int x)
{
x = x;
}
//???fputc??
int fputc(int ch, FILE *f)
{
while((USART1->SR&0X40)==0);//????,??????
USART1->DR = (u8) ch;
return ch;
}
#endif
void Usart_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructrue;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_PinAFConfig(GPIOA,GPIO_Pin_9,GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA,GPIO_Pin_10,GPIO_AF_USART1);
GPIO_InitStructrue.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructrue.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructrue.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructrue.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructrue.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA,&GPIO_InitStructrue);
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_Mode =USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART1,&USART_InitStructure);
//USART_ITConfig(USART1,USART_IT_RXNE, ENABLE);
//USART_ITConfig(USART1,USART_IT_TC, ENABLE);
USART_Cmd(USART1,ENABLE);
USART_ClearFlag(USART1, USART_FLAG_TC);
//USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
#ifndef USART_H
#define USART_H
#include "stm32f4xx_conf.h"
void Usart_Config(void);
#endif
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>