AnsweredAssumed Answered

Why does HAL_UART_Receive keep crashing?

Question asked by Andrew Hazelton on Sep 26, 2017
Latest reply on Oct 8, 2017 by Andrew Hazelton

Hi. Can someone please help me see where I am going wrong? The program will transmit the UART message but crashes when it gets to the "HAL_UART_Receive" function. I am using the STM32F746 Discovery Board.

 

UART_HandleTypeDef MobileGNSSUartHandle;
uint8_t UART_Rx_Buffer[100];
uint8_t UART_Tx_Buffer[] = "AT\r";

GPIO_InitTypeDef GPIO_InitStruct;

HAL_Init();


/* Peripheral clock enable */
__HAL_RCC_USART6_CLK_ENABLE();

/**USART6 GPIO Configuration
PC7 ------> USART6_RX
PC6 ------> USART6_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

// Enable GPIOs clock
__HAL_RCC_GPIOC_CLK_ENABLE();

// Initialise UART6
MobileGNSSUartHandle.Instance = USART6;
MobileGNSSUartHandle.Init.BaudRate = 115200;
MobileGNSSUartHandle.Init.WordLength = UART_WORDLENGTH_8B;;
MobileGNSSUartHandle.Init.StopBits = UART_STOPBITS_1;
MobileGNSSUartHandle.Init.Parity = UART_PARITY_NONE;
MobileGNSSUartHandle.Init.Mode = UART_MODE_TX_RX;
MobileGNSSUartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
MobileGNSSUartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
MobileGNSSUartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
MobileGNSSUartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
HAL_UART_Init(&MobileGNSSUartHandle);

 

HAL_UART_Transmit( &MobileGNSSUartHandle, (uint8_t *)UART_Tx_Buffer, 3, 5000 );
HAL_UART_Receive( &MobileGNSSUartHandle, (uint8_t *)UART_Rx_Buffer, 4, 5000 );

Outcomes