stm32f103 串口1 调试正常,串口3不能发送出数据,请高手们帮我看看,什么问题,谢谢
下面是串口1和串口3的程序,串口3由PB10(TXD)和PB11(RXD),组成,现在串口3数据发送不出来。不知哪里有问题,请高手指教。
void uart_init(u32 bound)
{ // GPIO 端口设置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE); USART_DeInit(USART1); //复位串口1
USART_DeInit(USART3); //复位串口3
//USART1_TX PA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure); //PA9
//USART1_RX PA.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Usart1
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = bound;// 设置波特率
USART_InitStructure.USART_WordLength = USART_WordLength_9b;//8位数据1位奇数校验
USART_InitStructure.USART_StopBits = USART_StopBits_1;//1个停止位
USART_InitStructure.USART_Parity = USART_Parity_Odd; // USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;// USART_InitStructure.USART_Mode =/*SART_Mode_Rx |*/ USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure); //
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//
USART_Cmd(USART1, ENABLE);
// =======================usart 3 I/O PB.10=>TXD, PB.11==>RXD Begin ================
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); //
//USART3_Txd PB.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PB.10
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART3_RX PB.11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//
GPIO_Init(GPIOB, &GPIO_InitStructure);
// =======================usart 3 I/O PB10=>TXD, PB11==>RXD End ================
USART_InitStructure.USART_BaudRate = bound;//波特率19200;
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(USART3, &USART_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure); //¸
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//
USART_Cmd(USART3, ENABLE);
}
发送程序:
int txd_fs3(u8 ch) {
while((USART3->SR&0X40)==0)
USART3->DR = (u8) ch;
return ch;
}
在main.c中调用
uart_init(19200);
txd_fs3(0x45);
txd_fs3(0x45);
串口3数据发送不出来。不知问题在什么地方?