|
最近在搞着玩的时候无意中把串口读取输出程序死循环执行了,导致串口不断被占用,用普中的STM32烧写程序无论波特率设置成什么都烧写不进去程序,请问有什么解决方法。
下面是错误代码,希望有人帮忙解决一下,多谢。
#include <stdio.h>
#include "stm32f10x.h"
#include "math.h"
//---------------------------------------------------------------------------------------
void uart1_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE); //使能USART1和GPIOA时钟
USART_DeInit(USART1); //复位串口1(各参数置为缺省值)
//USART1_TX(发送数据) PA.9引脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA.9
//USART1_RX(接收数据) PA.10引脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA.10
//NVIC中断向量配置
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=4 ;//抢占优先级置为3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4; //子优先级置为3,优先级依据不同的中断重要性不同来确定。
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据上面设置的参数初始化NVIC寄存器
//USART初始化设置
USART_InitStructure.USART_BaudRate = bound;//设置波特率;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据
USART_InitStructure.USART_StopBits = USART_StopBits_1;//1个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART1, &USART_InitStructure); //串口初始化
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//中断开启
USART_Cmd(USART1, ENABLE); //串口使能
}
//------------------------------------------------------------------------------------------
void main()
{
uart2_init(115200);
uart1_init(115200);
u16 a;
while(1)
{
a=USART_ReceiveData(USART1);
USART_SendData(USART1,a);
}
}
|
|