2016-09-23 01:51 AM
Hello,
I am writing to ask about the possibility of an error.
I have STM32F429ZTI Discovery board and FreeFRTOS with HAL driversrunning on it. I would like to implement communication via serialport (UART5 in my case). The problem is that i can't read any data.
I can send data and everything is ok but when i want to recieve datanothing happen.
I find out that function „HAL_UART_RxCpltCallback�? in not called. Iknow that Hardware is OK, because i have other project on this boardwith standard liblary and I can send and recieve data.
At the bottom I include my code.
If anybody know what it could be I will be very happy for answer.
Thanks
ADC_HandleTypeDef hadc1;
UART_HandleTypeDef huart5;
UART_HandleTypeDef UartHandle;
DMA_HandleTypeDef hdma_uart5_tx;
__IO ITStatus UartReady = RESET;
unsigned
char
data_to_send[3] = {0xAA, 0xBB, 0xCC};
unsigned
char
data_to_read[3];
void
InitUART5(
void
){
GPIO_InitTypeDef GPIO_InitStruct;
/* Peripheral clock enable */
__HAL_RCC_UART5_CLK_ENABLE();
__GPIOD_CLK_ENABLE();
__GPIOC_CLK_ENABLE();
/*
UART5 GPIO Configuration
PC12 ------> UART5_TX
PD2 ------> UART5_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_UART5;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_UART5;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
huart5.Instance = UART5;
huart5.Init.BaudRate = 115200;
huart5.Init.WordLength = UART_WORDLENGTH_8B;
huart5.Init.StopBits = UART_STOPBITS_1;
huart5.Init.Parity = UART_PARITY_NONE;
huart5.Init.Mode = UART_MODE_TX_RX;
huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart5.Init.OverSampling = UART_OVERSAMPLING_16;
if
(HAL_UART_Init(&huart5) != HAL_OK)
{
Error_Handler();
}
__HAL_UART_ENABLE_IT( &huart5,UART_IT_RXNE);
HAL_NVIC_SetPriority(UART5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(UART5_IRQn);
HAL_UART_Receive_IT(&huart5, data_to_read, 3);
}
void
HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart5)
{
UartReady = SET;
}
void
HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart5)
{
if
(huart5->Instance == UART5){
BSP_LED_Toggle(0);
int
i;
for
(i = 0; i < 3 ;i++){
data_to_send[i] = data_to_read[i];
}
HAL_UART_Receive_IT(&huart5, data_to_read, 3);
HAL_UART_Transmit_IT(&huart5, data_to_send, 3);
}
}
void
UART5_IRQHandler(
void
)
{
HAL_UART_IRQHandler(&huart5);
}
#hal #uart5 #usart #stm32f4
2016-09-30 04:20 AM
Hi ,
IT is a matter of pointer that should be passed into the __Hal_UART_Receive_IT() function. Try to change the data-to-read buffer initialization to this:/* Buffer used for reception */
uint8_t data-to-read[3];
and call receive function as follow:
HAL_UART_Receive_IT(&huart5, (uint8_t*)data_to_read, 3);
-Hannibal-
2016-10-02 10:08 AM
Hi,
You do not describe how you are sending input to your program. The Rx_Complete interrupt occurs when the receive buffer is full, not on each character. So if you are not inputting 3 characters you will not see the interrupt. If you want to get whatever characters have been input at any time, you need to manage the buffer yourself and extract characters when they are available.