stm32f103zet6 串口5无法接收数据
相同配置下串口3和串口1能够收发数据
不能进入中断函数
/* UART3 Buffer Defines */
#define USART5_RX_BUFFER_SIZE 64 /* 2,4,8,16,32,64,128 or 256 bytes */
#define USART5_TX_BUFFER_SIZE 256 /* 2,4,8,16,32,64,128 or 256 bytes */
#define USART5_RX_BUFFER_MASK ( USART5_RX_BUFFER_SIZE - 1 )
#define USART5_TX_BUFFER_MASK ( USART5_TX_BUFFER_SIZE - 1 )
UartRxBuffer USART5_Rx_Buffer;
void UartInit(void)
{
UartBufferInit();
Uart5Init();
UartNVIC();
}
void UartBufferInit()
{
USART5_Rx_Buffer.buffer = (u8*)malloc(USART5_RX_BUFFER_SIZE);
memset(USART5_Rx_Buffer.buffer,0,USART5_RX_BUFFER_SIZE);
USART5_Rx_Buffer.index = 0;
USART5_Rx_Buffer.maxSize = USART5_RX_BUFFER_SIZE;
}
void Uart5Init(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1 Periph_UART5,ENABLE);
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_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(UART5, &USART_InitStructure);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
USART_Cmd(UART5, ENABLE);
USART_ClearFlag(UART5, USART_FLAG_TC);
}
void UartNVIC(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void UART5_IRQHandler(void)
{
u8 res;
if(USART_GetFlagStatus(UART5,USART_FLAG_ORE)==SET)
{
USART_ClearFlag(UART5,USART_FLAG_ORE);
res = USART_ReceiveData(UART5);
if(USART5_Rx_Buffer.index < USART5_Rx_Buffer.maxSize)
{
USART5_Rx_Buffer.buffer[USART5_Rx_Buffer.index] = res;
USART5_Rx_Buffer.index ++;
}
}
if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
{
res =USART_ReceiveData(UART5);
if(USART5_Rx_Buffer.index < USART5_Rx_Buffer.maxSize)
{
USART5_Rx_Buffer.buffer[USART5_Rx_Buffer.index] = res;
USART5_Rx_Buffer.index ++;
}
}
if(USART_GetITStatus(UART5, USART_FLAG_TC) != RESET)
{
return ;
}
}
void IoInit(void)
{
//PORTA
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOG|RCC_APB2Periph_GPIOF|
RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIO_InitStructure.GPIO_Pin= GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}