cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with UART HAL DRIVER function.

juanjojy
Associate
Posted on May 25, 2015 at 00:35

Hi, i was trying to learn how to use the UART from m stm32f429DISCO, starting with a simple polling program that reads a caracter from pc and retransmit it. (i've reviewed reference manual, datasheet and the description of hal drivers pdf) but can't find the reason why the HAL_UART_Receive(); doesnt change the rxbuffer at all.

I use abother board as usb to 232 converter  and coolterm to send the data.

I've used cubeMX to configure UART 7 port and verified how it set my GPIOF pins 6 and 7 as RX and TX. I've checked the uart configuration matching in my coolterm and the program. and used the solution suggested by 

Heisenberg in 

/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Best%20way%20to%20use%20HAL%20UART%20Receiver%20IT%20Function&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=4963

/* Includes ------------------------------------------------------------------*/

&sharpinclude ''stm32f4xx_hal.h''

/* USER CODE BEGIN Includes */

/* Private variables ---------------------------------------------------------*/

UART_HandleTypeDef huart7;

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_UART7_Init(void);

int main(void)

{

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

  HAL_Init();

  /* Configure the system clock */

  SystemClock_Config();

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_UART7_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */

  /* USER CODE BEGIN WHILE */

 

  uint8_t aTxBuffer[2];

aTxBuffer[0]=0x30;

aTxBuffer[1]=0x31;

uint8_t aRxBuffer[2];

HAL_StatusTypeDef UARTStatus;

while (1){

UARTStatus =  HAL_UART_Receive(&huart7,(uint8_t *)aRxBuffer, 2, 5000); 

while((UARTStatus != HAL_OK) || (UARTStatus != HAL_TIMEOUT)){

aTxBuffer[0]=aTxBuffer[0]+aRxBuffer[0];

aTxBuffer[1]=aTxBuffer[1]+aRxBuffer[1];

UARTStatus2=HAL_UART_Transmit(&huart7,(uint8_t*)aTxBuffer,2, 5000);

    while((UARTStatus2 != HAL_OK) || (UARTStatus != HAL_TIMEOUT)){

}

HAL_UART_Receive(&huart7,(uint8_t *)aRxBuffer, 2, 5000); 

}

  }//fwhile 

}//FMAIN

----------------

The program is supposed to change what is shown on the terminal in some way but i keep getting the eternal 0101010101

and it doesnt change no matter how many keys i press... any ideas of what im doing wrong?

#hal #uart #stm32f429 #polling
2 REPLIES 2
fenugrec
Associate II
Posted on May 26, 2015 at 16:54

Hi,

You may be using the HAL functions incorrectly. For example,

UARTStatus2=HAL_UART_Transmit(&huart7,(uint8_t*)aTxBuffer,2, 5000);

while((UARTStatus2 != HAL_OK) || (UARTStatus != HAL_TIMEOUT)){

}

This transmits 2 bytes from the buffer and HAL_UART_Transmit() returns when it's done. So the while() loop is useless (UARTStatus2 will not change after the Transmit call). Maybe you were looking for non-blocking functions ?

Also, your first ''while (UARTStatus != OK || UARTStatus != Timeout) {...} '') is suspicious, for the same reason: HAL_UART_Receive() is blocking. 

juanjojy
Associate
Posted on May 29, 2015 at 05:57

Thanks, got it working now, i had bad understanding of it, now after a few days of reading i'm not doing those silly things anymore. Now im into non blocking mode. Thanks for your interest.