cancel
Showing results for 
Search instead for 
Did you mean: 

Question about: if (__HAL_UART_GET_FLAG(&huart3, UART_FLAG_RXNE) == SET) condition

ABras.1
Associate II

Hello everyone, i have a problem about this condition, i use it for transmit a only one character to a function ( ChooseMenu )

Actually i convert decimal to ascii with if condition..

	  if (__HAL_UART_GET_FLAG(&huart3, UART_FLAG_RXNE) == SET)
	  		{
	  			uint8_t value;
	  			uint8_t value2;
	  			HAL_UART_Receive(&huart3, &value, 1, 100);
	  			if (value == 48){
	  				value2 = 0;
	  			}
	  			if (value == 49){
	  				value2 = 1;
	  			}
	  			if (value == 50){
	  				value2 = 2;
	  			}
	  			if (value == 51){
	  				value2 = 3;
	  			}
	  			ChooseMenu(value2);
	  		}

I have two question

1 : how to convert decimal to ascii ? when a write "1" in my serial monitor, it's not 1 in ascii but 48 in decimal but i need to transmit 1 to my menu not 48

2 : When i use 9600 baud if I write 1 many time, it crash i can't transmit other value but if i use 115200 baud, i did not crash why ?

I use STM32F746ZG

thanks for you help !

3 REPLIES 3

itoa()

value2 = value - 48;​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ABras.1
Associate II

How i can with Itoa i check and, it seems itao() do not convert decimal to character ?

I think that @Community member​ is meaning atoi(), not itoa().

Please check atoi().

Regards