帮忙看看这个串口程序怎么不对
#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:帮忙看看这个串口程序怎么不对
串口的rcc没有enbaleRE:帮忙看看这个串口程序怎么不对
同意楼上,串口时钟没开RE:帮忙看看这个串口程序怎么不对
你的意思是RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);这一句吗
RE:帮忙看看这个串口程序怎么不对
有一句RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);这个也一样的吧
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初始化前面
页:
[1]