USART1 - interrupt problem with STM32F051
Dear community,
I am trying to initialize the UART of the STM32F051 µC – however receiving of data does not work because the interrupt is not triggered. I recognized only the weak initialization of the UART1 interrupt handler in the startup file so I added myself the required lines. Unfortunately it does not work. I would be very happy if someone could check the following code for mistakes.
void COM_USART1_Init() { //COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct) GPIO_InitTypeDef GPIO_InitStructure1; //GPIO STruct GPIO_InitTypeDef GPIO_InitStructure2; //GPIO STruct USART_InitTypeDef USART_InitStructure; //USART Struct NVIC_InitTypeDef NVIC_InitStructure; //for USART //GPIO for USART RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //GPIOA_AHBPeriph_CLOCK // Configure the GPIO_struct USART Tx as alternate function push-pull GPIO_InitStructure1.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure1.GPIO_OType = GPIO_OType_PP; //PushPull (Gegentakt) GPIO_InitStructure1.GPIO_PuPd = GPIO_PuPd_UP; //NO Pull GPIO_InitStructure1.GPIO_Speed = GPIO_Speed_10MHz; // Configure the GPIO_struct USART Rx as alternate function push-pull GPIO_InitStructure2.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure2.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure2.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure2.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure2.GPIO_Speed = GPIO_Speed_10MHz; //Init GpioStruct GPIO_Init(GPIOA, &GPIO_InitStructure1); GPIO_Init(GPIOA, &GPIO_InitStructure2); GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1); //Connect the PINS and USART BUS GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); //NVIC for USART USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // enable the USART1 receive interrupt USART_ITConfig(USART1, USART_IT_TXE, ENABLE); // enable the USART1 send interrupt // Enable the USARTx Interrupt NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //USART 1 // USARTx configured as follow: // - BaudRate = 115200 9600 baud // - Word Length = 8 Bits // - One Stop Bit // - No parity // - Hardware flow control disabled (RTS and CTS signals) // - Receive and transmit enabled RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //ENABLE USART3 CLK USART_InitStructure.USART_BaudRate = 115200;/ 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 configuration USART_Init(USART1, &USART_InitStructure); // Enable USART USART_Cmd(USART1, ENABLE);}void USART1_IRQHandler (void) {if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { unsigned char received = USART_ReceiveData(USART1); //Receiver //set DAC }}//STARTUPCODE.sUSART1_IRQHandler PROC EXPORT USART1_IRQHandler [WEAK] B . ENDP ; EXPORT USART1_IRQHandler [WEAK] ; EXPORT USART1_IRQHandler [WEAK]Thank you very much for reviewing my code.