2016-02-10 12:40 AM
Hi all,
I'm working with STM32F4 mcu and keil uVision 5 IDE. I'm tryng to configure RS232 periph. but I have a problem. Transmission works fine but I'm not able to receive interrupt when something is received. Here my code:
/** Init Rs232 port
*/
void init_RS232(void){
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__GPIOC_CLK_ENABLE();
__USART3_CLK_ENABLE();
/**USART3 GPIO Configuration
PC10 ------> USART2_TX
PC11 ------> USART2_RX
*/
/*Configure GPIO pin : RS232 Pin */
GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* Configure USART3 parameters */
USART3_Handle.Instance = USART3;
USART3_Handle.Init.BaudRate = 9600;
USART3_Handle.Init.Mode = USART_MODE_TX_RX;
USART3_Handle.Init.Parity = USART_PARITY_NONE;
USART3_Handle.Init.StopBits = USART_STOPBITS_1;
USART3_Handle.Init.WordLength = USART_WORDLENGTH_8B;
HAL_USART_Init(&USART3_Handle);
HAL_USART_Receive_IT(&USART3_Handle, rx_buffer, 16);
HAL_NVIC_SetPriority(USART3_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(USART3_IRQn);
}
I would to receive an interrupt every time a char is received and I would like to manage by myself the buffer. With old lib (standard periph lib) I was able to do this. With new HAL ones not.
Can you help me?
Thanks a lot.
2016-02-10 01:52 AM
HAL_USART_Receive_IT
''2016-02-10 03:21 AM
Hi,
I've tried your suggestion but it doesn't work. When I enable IRQ the transmission doesn't work too. The code fall continously in USART3_IRQHandler.2016-02-10 07:43 AM
Have anyone an example for this problem?
2016-02-10 08:05 AM
Doesn't HAL/Cube have a load of examples it installs?
2016-02-10 08:06 AM
Hi crazy_code,
In the STM32CubeF4 package, there are several examples for USART/UART based on interrupt mode (Ex:STM32Cube_FW_F4_V1.11.0\Projects\STM32F4-Discovery\Examples\UART\UART_TwoBoards_ComIT).You may take them as start point to develop your own application.You can also generate your initialization code based on CubeMX, did you tried it?-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2016-02-10 08:17 AM
Hi Mayla,
can you explain me how to generate an example that uses UART and interrupt?I open CubeMX, select New Project, selct my mcu, add UART to periph and check NVIC global interrupt but in the code I cannot find IRQ configuration,Thanks a lot.2016-02-10 08:51 AM
You will find it in the file stm32f4xx_hal_msp.c.
-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2016-02-12 05:56 AM
Hi,
UART now works. I can transmit and receive in polling. I still have sompe problem with receive interrupt. I receive only first interrupt. Following ones are not detected. Here my code:void USART3_IRQHandler(void){
HAL_NVIC_ClearPendingIRQ(USART3_IRQn);
HAL_UART_IRQHandler(&USART3_Handle);
}
What's wrong?
2016-02-16 06:48 AM
Can anyone tell me if my IRQ handler is correct?
Thanks.