初级会员

- 积分
- 54
- 金钱
- 54
- 注册时间
- 2016-4-30
- 在线时间
- 8 小时
|
2金钱
用下边代码配置了串口1-8都可以使用,但是9和10不能使用是怎么回事啊?万分感谢
void uart9_init(u32 bound){
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB2Periph_UART9,ENABLE);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource14,GPIO_AF11_UART9);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource15,GPIO_AF11_UART9);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD,&GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = bound;
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(UART9, &USART_InitStructure);
USART_Cmd(UART9, ENABLE);
#if EN_USART9_RX
USART_ITConfig(UART9, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = UART9_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#endif
}
void UART9_IRQHandler(void)
{
u8 temp;
if(USART_GetITStatus(UART9, USART_IT_RXNE) != RESET)
{
temp = USART_ReceiveData(UART9);
USART_ClearITPendingBit(UART9, USART_IT_RXNE);
USART_SendData(USART1, temp);
}
}
|
|