这个是我的配置:
void uart4_init(u32 bound)
{
//GPIO端口设置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
// USART_ClockInitTypeDef USART_ClockInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE);
//USART4_TX PC10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//USART4_RX PC11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//Usart1 NVIC 配置
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; //0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器USART1
USART_InitStructure.USART_BaudRate = bound;//一般设置为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(UART4,&USART_InitStructure);
USART_ITConfig(UART4,USART_IT_RXNE,ENABLE);//开启中断
USART_Cmd(UART4,ENABLE); //使能串口
//UART4->CR3|=1<<7;
}
void UART4_IRQHandler(void)
{
u8 ch;
if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET)
{
ch = USART_ReceiveData(UART4);
uart4_buf[uart4_count]=ch;
uart4_count++;
uart4_count&=0xff;
delay_uart4=5;
}
}
遇到的问题是这样的:
我从串口一发送数据,然后从串口4发送出来,没有问题。
可是我从串口4发送数据,就死机不能从串口一发送出来了。
开了看门狗,串口4接收数据就重启了。
|