中级会员
 
- 积分
- 399
- 金钱
- 399
- 注册时间
- 2014-11-7
- 在线时间
- 44 小时
|
5金钱
为什么串口2不工作呢??? 与APB1的时钟有关,表示不懂
void USART2_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* config USART2 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
/* USART2 GPIO config */
/*Configure USART2 Tx (PA.02)as push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //选择 2 引脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置引脚速率为50Mhz
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //选择 3 引脚
GPIO_Init(GPIOA,&GPIO_InitStructure);
/* USART2 mode config */
USART_InitStructure.USART_BaudRate = 9600;
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;
USART_Init(USART2,&USART_InitStructure);
USART_Cmd(USART2,ENABLE);
}
void USART2_Send_String(char *String)
{
while(*String)
{
USART_SendData(USART2,*String++);
while( USART_GetFlagStatus(USART2,USART_FLAG_TXE)== RESET);
}
}
|
|