Question
Problem with the interrupt of UART4 of processor STM32F072CBT6
Posted on November 22, 2015 at 21:54 hello, I'm having a problem with the UART4 of the processor STM32F072CBT6 when the interrupt of the UART is enabled. Lets me shot the code: #include ''stm32f0xx.h'' #include ''stm32f0xx.h'' #include ''stm32f0xx_usart.h'' #include ''stm32f0xx_misc.h'' void initUSART(void); void sendStringUart(char *data); void sendCharUart(char data); volatile char receiverBufferUart[256]; int possitionUart; //possition of next byte of receiveerBuffer void initUSART(){ USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART4, ENABLE); GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_4); GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_4); /* Configure USART4 pins: Rx and Tx ----------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Enable USART4 IRQ */ NVIC_InitStructure.NVIC_IRQChannel = USART3_4_IRQn;//USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); 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_Init(USART4, &USART_InitStructure); // Habilita a interrupcao USART_ITConfig(USART4, USART_IT_RXNE, ENABLE); USART_Cmd(USART4,ENABLE); } void sendCharUart(char data){ while (USART_GetFlagStatus(USART4, USART_FLAG_TXE) == RESET); USART_SendData(USART4, data); } void sendStringUart(char *data){ int i=0; for(;data[i] !=0 ;i++){ sendCharUart(data[i]); } } void USART3_4_IRQHandler(void) { /* RXNE handler */ if(USART_GetITStatus(USART4, USART_IT_RXNE) != RESET) { receiverBufferUart[possitionUart] = USART_ReceiveData(USART4); } } int main(void){ initUSART(); sendStringUart(''hello world\n''); while(1); return 0; } When I execute this code the processor broke in the function HardFault_Handler () at stm32f0xx_it.c:67 - I discovery it using the GDB. However when I comment the line USART_ITConfig(USART4, USART_IT_RXNE, ENABLE); it work very well, but without interrupt. Anyone was this problem? Is some bug of the processor? My code is wrong? Sorry for my bad English. Thanks
Note: this post was migrated and contained many threaded conversations, some content may be missing.
