最近写了一个串口的程序,用的STM32F103的UART2和UART3,UART发送数据,UART3接收数据,具体的程序如下,但是现在UART2能正常发送数据但是UART3无法接收到程序,UART3的接收数据的寄存器都没有数据,但是我是讲UART2的发送口连接到UART3的接收口了的啊!求教???????
#include "stm32f10x.h"
uint8_t UART, i=0, nn;
void GPIO_Configuration(void);
int main(void)
{
USART_InitTypeDef USART_InitStructure;
SystemInit();
GPIO_Configuration();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 | RCC_APB1Periph_USART3, ENABLE);
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_Init(USART3, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
USART_Cmd(USART3, ENABLE);
USART_HalfDuplexCmd(USART2, ENABLE);
USART_HalfDuplexCmd(USART3, ENABLE);
USART_ClearFlag(USART2, USART_FLAG_TC);
USART_ClearFlag(USART3, USART_FLAG_RXNE);
while (1)
{
i++;
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, i);
if (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET)
{
UART = USART_ReceiveData(USART3);
// UART++;
// while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
// USART_SendData(USART3, UART);
}
// if (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == SET)
// {
// nn = USART_ReceiveData(USART2);
// }
}
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //上啦输入
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //上啦输入
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
|