2013-09-23 02:33 AM
Hi,
I configured USART1 in stm32f051c8t6 but when i run the code on my h/w it goes hang. I dont where it is hanging. whether because of NVIC OR USART. But according to me it hang in NVIC because everything run ok.......... Please help me resolve this issues..... I have given my configuration bellow;; RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE) ; RCC_USARTCLKConfig(RCC_USART1CLK_SYSCLK); GPIO_InitStructure.GPIO_Pin = UART_TX_PIN ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2; GPIO_Init(UART_TX_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = UART_DTR_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2; GPIO_Init(UART_DTR_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = UART_RX_PIN ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(UART_RX_PORT, &GPIO_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_DeInit(USART1); 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_Mode = USART_Mode_Tx | USART_Mode_Rx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_Init(USART1, &USART_InitStructure); // USART_ITConfig(USART1, USART_IT_TXE, DISABLE); USART_ITConfig(USART1, USART_IT_TC, ENABLE); USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); USART_Cmd(USART1, ENABLE); /////////////////UART1 IRQ handler?????????????????????? void USART1_IRQHandler(void) { if(USART_GetITStatus(USART1, USART_IT_RXNE)!= RESET) { USART_ClearITPendingBit(USART1, USART_IT_RXNE); } if(USART_GetITStatus(USART1, USART_IT_TC)!= RESET) { USART_ClearITPendingBit(USART1, USART_IT_TC); send_ctr++; if(send_ctr <= 13) { uart_send_data = uart_msg[send_ctr]; USART_SendData(USART1, uart_send_data); } else send_ctr = 0; } } #provide-complete-code #stm32f051c8t6-usart-hanging-prob2013-09-23 04:40 AM
Needs RX configured as AF, please refer to other examples
You have an RXNE interrupt but really don't service the USART by reading it's data register. You use the TC interrupt when TXE would be better. It's not clear how your code ever sends the first element of the array, or if it ever stops sending data. Likely gets stuck in interrupt state because RXNE not cleared.2013-09-24 04:49 AM