我用的是
STM32F030K6
串口初始化程序如下:
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 , ENABLE );
/*********ÅäÖÃUART1********************/
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_0); //PB6 PB7?????UART1
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_0); //?????????(?????)
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_0);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_0);
/* Configure USART Tx as alternate func
tion push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART Rx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_Init(GPIOB,&GPIO_InitStructure);
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_Tx | USART_Mode_Rx ;
USART_Init(USART1, &USART_InitStructure);
// USART_ITConfig(USART1, USART_IT_TC, ENABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
NVIC_InitTypeDef NVIC_InitStructconfig;
NVIC_InitStructconfig.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructconfig.NVIC_IRQChannelPriority = 1;
NVIC_InitStructconfig.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructconfig);
串口中断函数如下:
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
UsartType.RX_pData[UsartType.RX_Size++]=(USART1->RDR & (uint16_t)0x01FF);
USART_SendData(USART1,USART1->RDR);
if(UsartType.RX_Size>=200)
{
UsartType.RX_Size=0;
}
USART_ClearFlag(USART1,USART_IT_RXNE);
}
}
函数功能就是串口把接收到的数据再发出来。
目前的现象是在中断函数设置一个断点,进入断点后再全速运行,就接收不到数据了,无法进入中断。
哪位大神知道问题在哪
全速运行没问题,就是如果调试程序的话,进入其他地方的断点(不在中断函数内)后,再全速运行也无法接收到数据。
中断标志位没有变化 可以进中断 但是标志位进不去
一周热门 更多>