初级会员

- 积分
- 173
- 金钱
- 173
- 注册时间
- 2018-6-1
- 在线时间
- 20 小时
|
2金钱
#include "stm32f10x.h"
#include "usart.h"
#include "delay.h"
#include "stdint.h"
void My_USART3_Init(void)
{
GPIO_InitTypeDef GPIO_InitStrue;
USART_InitTypeDef USART_InitStrue;
NVIC_InitTypeDef NVIC_InitStrue;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//¢ù
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStrue.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStrue.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStrue);//¢ú
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_InitStrue.GPIO_Pin=GPIO_Pin_11;
GPIO_InitStrue.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStrue);//¢ú
USART_InitStrue.USART_BaudRate=115200;
USART_InitStrue.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStrue.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
USART_InitStrue.USART_Parity=USART_Parity_No;
USART_InitStrue.USART_StopBits=USART_StopBits_1;
USART_InitStrue.USART_WordLength=USART_WordLength_8b;
USART_Init(USART3,&USART_InitStrue);//¢Û
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);//¿aÆô½óêÕÖD¶Ï
NVIC_InitStrue.NVIC_IRQChannel=USART3_IRQn;
NVIC_InitStrue.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStrue.NVIC_IRQChannelSubPriority=1;
NVIC_InitStrue.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStrue);
USART_Cmd(USART3,ENABLE);//ê1Äü′®¿ú3
}
void USART3_IRQHandler(void)
{
u8 res;
USART_ClearFlag(USART3,USART_FLAG_TC);
if(USART_GetITStatus(USART3,USART_IT_RXNE)!=RESET)
{
res= USART_ReceiveData(USART3);
USART_SendData(USART3,res);
while(USART_GetFlagStatus(USART3,USART_FLAG_TXE)==RESET);
printf("1\r\n");
}
}
int main(void)
{
uint16_t i;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
My_USART3_Init();
delay_init();
for(i=1;i<=9;i++)
{
USART_SendData(USART3,i);
}
while(1);
}
各位师傅们:我有两个问题:
首先我的板子是STM32F103RCT6的
1:该怎么用串口1去判断程序进行到了那里呢?
2:这个串口3发送的数据为什么没有达到我想要的:按下按键,XCOM里输出1-9的数字?
请师傅们不吝赐教 ,谢谢谢谢!
|
最佳答案
查看完整内容[请看2#楼]
1,通过printf输出。
2,USART_SendData(USART3,i);后必须等待发送完成,否则不会发送出你想要的所有数据。
|