最近有个项目要用到STM32F071芯片的串口三,以前调试1和2都没有问题,但是配置好串口三以后就开始死机,我说明下情况:
首先使用内部时钟,设置如下:
RCC_DeInit();// ½«ÍâÉèRCC¼Ä´æÆ÷ÉèÖÃΪȱʡֵ
RCC_HSICmd(ENABLE);// ʹÄÜÄÚ²¿HSI
while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET)// µÈ´ýHSIʹÄܳɹ¦
{
}
if(1)
{
// FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
// FLASH_SetLatency(FLASH_Latency_2);
RCC_HCLKConfig(RCC_SYSCLK_Div1); // ϵͳÄÚ²¿Ê±ÖÓ
RCC_PCLKConfig(RCC_HCLK_Div1); // APBʱÖÓÉèÖÃ
// PLL±¶Æµ£¬8MÄÚ²¿¾§Õñ£¬12±¶Æµºó»ñµÃ48MʱÖÓ
RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_2);
// ʹÄÜPLL
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) // ±¶Æµ³É¹¦
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
然后使用PB10-TX3,PB11-RX3,配置如下:
// PB10--W_TXD,PB11--W_RXD
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);// ʹÄܶ˿ÚʱÖÓ
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10,GPIO_AF_1); // ¶Ë¿Ú¸´ÓÃÑ¡Ôñ
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11,GPIO_AF_1); // ¶Ë¿Ú¸´ÓÃÑ¡Ôñ
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; //ÉèÖö˿ڸ´ÓÃ
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11,GPIO_AF_4); // ¶Ë¿Ú¸´ÓÃÑ¡Ôñ
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; //ÉèÖö˿ڸ´ÓÃ
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
然后配置串口三相关信息如下:
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure; // ÖжϲÎÊý
USART_ITConfig(USART3,USART_IT_RXNE,DISABLE);
USART_Cmd(USART3, DISABLE);
RCC_APB1PeriphClockCmd(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(USART3, &USART_InitStructure);
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
// USART_ITConfig(USART3,USART_IT_CTS,DISABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART3_4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_Cmd(USART3, ENABLE);
我就配置完了串口三,也没有发送接收数据,然后运**死在startup_stm32f072.s中,如下如:
USART3_4_IRQHandler
CEC_CAN_IRQHandler
USB_IRQHandler
B .
ENDP
ALIGN
卡在B .这个位置了,我是完全蒙圈了,搞不明白了,在此求教各位大神怎么回事。还有,经过测试
将 NVIC_Init(&NVIC_InitStructure);屏蔽掉就不会卡死.....谢谢 |