AnsweredAssumed Answered

STM32F4 with HAL drivers – Recive data doesn't work

Question asked by warcho_.grzegorz on Sep 23, 2016
Latest reply on Oct 2, 2016 by bauch.aaron.001

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);
 
 
}


Outcomes