Question
USART interrupt problem
Posted on December 30, 2015 at 12:18
I'm using a stm32f10x micorcontroller (steval-mki121v1 evaluation board) and i want to enable an interrupt event when a data is receive through the USART.
The problem is that the interrupt never occurs after the data is send.here the code:void USARTInit(void){ USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef nvicStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); /* Configure USART Tx as alternate function push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART Rx as input floating */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &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(USART2, &USART_InitStructure); USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //USART_ClearITPendingBit(USART2,USART_IT_RXNE); need this? //NVIC_EnableIRQ(USART2_IRQn); need this? nvicStructure.NVIC_IRQChannel = USART2_IRQn; nvicStructure.NVIC_IRQChannelPreemptionPriority = 0; nvicStructure.NVIC_IRQChannelSubPriority = 0; nvicStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&nvicStructure); USART_Cmd(USART2,ENABLE);}void USART2_IRQHandler() // never go here{ if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) { char data = 0; data = USART_ReceiveData(USART2); USART_ClearITPendingBit(USART2,USART_IT_RXNE); }}Edit: the trasmission working good instead. it is just not receiving data.