#include "stm32f4xx.h"
int main(void)
{
GPIO_InitTypeDef GPIO_initure;
USART_InitTypeDef USART_initure;
NVIC_InitTypeDef NVIC_initure;
USART_DeInit(USART1);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
GPIO_initure.GPIO_Pin=GPIO_Pin_9;
GPIO_initure.GPIO_Mode = GPIO_Mode_AF;
GPIO_initure.GPIO_OType=GPIO_OType_PP;
GPIO_Init(GPIOA,&GPIO_initure);
GPIO_initure.GPIO_Pin=GPIO_Pin_10;
GPIO_initure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_initure.GPIO_Mode = GPIO_Mode_IN;
GPIO_initure.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_Init(GPIOA,&GPIO_initure);
USART_initure.USART_BaudRate=115200;
USART_initure.USART_WordLength=USART_WordLength_8b;
USART_initure.USART_StopBits=USART_StopBits_1;
USART_initure.USART_Parity=USART_Parity_No;
USART_initure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_initure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_Init(USART1, &USART_initure);
USART_Cmd(USART1, ENABLE);
NVIC_initure.NVIC_IRQChannel=USART1_IRQn;
NVIC_initure.NVIC_IRQChannelPreemptionPriority=3;
NVIC_initure.NVIC_IRQChannelSubPriority=3;
NVIC_initure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_initure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
while(1)
{
}
}
void USART1_IRQHandler(void)
{
u16 Res;
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
Res =USART_ReceiveData(USART1);//(USART1->DR);
USART_SendData(USART1,Res);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
void USART1_IRQHandler(void)
{
u16 Res;
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_SendData(USART1,90);
}
} 这样就会自动发送数据了吗?
一周热门 更多>