STM32串口发送bob手机版网页体育问题
在串口1发送中,第一个字总是发不出来,单步调试发送正常,硬件上电复位发送不正常,发现是STM32上电复位后需要先读取USART_SR,然后写 USART_DR,解决办法在串口初始化加入USART_GetFlagStatus(USART2, USART_FLAG_TC);

void usart 1 _ Init(void){ GPIO _ Init typedef GPIO _ Init structure;USART _ init typedef USART _ init structure;//NVIC _初始化类型定义NVIC _初始化结构;

本文引用地址:http://www.eepw.com.cn/article/201611/318058.htm

RCC _ APB 2 periphclock cmd(RCC _ APB 2 periph _ gp IOA RCC _ APB 2 periph _ AFIO,使能);RCC _ APB 2 periphclock cmd(RCC _ APB 2 periph _ usart bob手机版网页体育 1,使能);

GPIO_InitStructure。GPIO _ Pin = GPIO _ Pin _ 9;GPIO_InitStructure。GPIO _ Mode = GPIO _ Mode _ AF _ PPGPIO_InitStructure。GPIO _ Speed = GPIO _ Speed _ 50MHzGPIO_Init(GPIOA,& GPIO _ Init structure);

GPIO_InitStructure。GPIO _ Pin = GPIO _ Pin _ 10GPIO_InitStructure。GPIO _ Mode = GPIO _ Mode _ IN _ FLOATING;GPIO_Init(GPIOA,& GPIO _ Init structure);

//NVIC _初始化结构。NVIC _ IRQ channel = usart 1 _ IRQn;//NVIC _初始化结构。NVIC _ IRQChannelPreemptionPriority = 3;//NVIC _初始化结构。NVIC _ IRQChannelSubPriority = 3;//

//NVIC _初始化结构。NVIC_IRQChannelCmd =使能;////NVIC _初始化(& NVIC _初始化结构);// - BaudRate = 115200波特// -字长= 8位// -一个停止位// -无奇偶校验// -硬件流控制禁用(RTS和CTS信号)// -接收和发送启用du start _ init structure。USART _ BaudRate = 9600USART_InitStructure。USART _ word length = USART _ word length _ 8b;USART_InitStructure。USART _ stop bits = USART _ stop bits _ 1;USART_InitStructure。USART bob手机版网页体育 _ Parity = USART _ Parity _ NoUSART_InitStructure。USART _ hardware flow control = USART _ hardware flow control _ None;USART_InitStructure。USART _ Mode = USART _ Mode _ Rx USART _ Mode _ Tx;USART_Init(USART1,& USART _ Init structure);

// USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//开始中断

USART_GetFlagStatus(USART1,USART _ FLAG _ TC);}

bob手机版网页体育
在线预约
TOP