#include "stm32f10x.h" void USART1_Init(void) { USART_InitTypeDef USART_InitStructure; 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_Tx|USART_Mode_Rx; USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None; USART_Init(USART1,&USART_InitStructure); USART_Cmd(USART1,ENABLE); } void USART1_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); 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); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA,&GPIO_InitStructure); } void Delay(vu32 nCount) { for(;nCount!=0;nCount--); } int main(void) { USART1_Init(); USART1_GPIO_Config(); while(1) { USART_SendData(USART1,‘a’); while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET); Delay(0xfff); } } |
RE:帮忙看看这个串口程序怎么不对
RE:帮忙看看这个串口程序怎么不对
RE:帮忙看看这个串口程序怎么不对
RE:帮忙看看这个串口程序怎么不对
这一句吗
RE:帮忙看看这个串口程序怎么不对
这个也一样的吧
RE:帮忙看看这个串口程序怎么不对
RE:帮忙看看这个串口程序怎么不对
void USART1_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Enable USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
//USART1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //USART1 TX
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure); //A端口
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //USART1 RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //复用开漏输入
GPIO_Init(GPIOA, &GPIO_InitStructure); //A端口
/* USART1 configuration ------------------------------------------------------*/
/* USART and USART2 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
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_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* Configure USART1 */
USART_Init(USART1, &USART_InitStructure);
/* Enable USART1 Receive and Transmit interrupts */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
/* Enable the USART1 */
USART_Cmd(USART1, ENABLE);
}:
回复:帮忙看看这个串口程序怎么不对
RE:帮忙看看这个串口程序怎么不对
结果是这个串口的GPIO定义必须要在USART初始化前面
回复:帮忙看看这个串口程序怎么不对
哈哈,终于找到问题了
结果是这个串口的GPIO定义必须要在USART初始化前面
祝贺你终于成功了。
建议把正确的代码再给大家贴一下吧,以便后人借鉴,谢谢~