最近我想利用
STM32驱动RC 522做一个读卡器,利用LCD显示(驱动SSD1289,利用FSMC),我买的模块是利用串口进行
通信的(模块另外集成了一个IC用于支撑串口通信)。我是利用串口2和RC 522通信,串口2初始化后,调用LCD初始化,然后LCD显示一些提示信息,但为题出在这里,我在主函数调用串口2初始化程序后,LCD显示碎屏,把串口2调用函数注释掉,LCD就能正确显示提示信息,我通过设置一些标志后推测程序是卡死在串口2初始化子函数这里所以导致LCD不显示。但我想不出为什么,串口2的初始化程序如下:
void Uart2Init(void)02{
03 USART_InitTypeDef USART_InitStructure;
04 GPIO_InitTypeDef GPIO_InitStructure;
05 NVIC_InitTypeDef NVIC_InitStructure;
06 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
07 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
08 USART_DeInit(USART2);
09 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;//TX
10 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
11 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
12 GPIO_Init(GPIOA, &GPIO_InitStructure);
13
14 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//RX
15 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOA
tiNG;
16 GPIO_Init(GPIOA, &GPIO_InitStructure);
17
18 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
19 NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
20 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
21 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
22 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
23 NVIC_Init(&NVIC_InitStructure);
24
25 USART_InitStructure.USART_BaudRate = 9600;
26 USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
27 USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
28 USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
29 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
30 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
31 USART_Init(USART2, &USART_InitStructure);
32 USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
33 USART_ITConfig(USART2, USART_IT_TC, ENABLE);
34 USART_Cmd(USART2, ENABLE);
35 USART_ClearFlag(USART2, USART_FLAG_TC);
36}请大虾指点
一周热门 更多>