2022-06-28 06:19 PM
Hi everyone, i see a warning when i write the code;
--> HAL_UART_Receive(&huart3, &Rx_Byte[0], 1, 10);
Rx_Byte is;
--> char Rx_Byte[1];
Why i see this warning can anyone help me?
Solved! Go to Solution.
2022-06-29 01:26 AM
@MKork.2 "because of i am new on stm. Why uint8_t ?"
It has nothing specifically to do with STM - this is standard C stuff:
You are correct in using char for plain, printable ASCII text - that is what it's for.
However, HAL_UART_Receive() is not restricted to plain text; it handles any arbitrary byte values - hence it uses uint8_t.
You could suppress the warning by casting your char value; eg,
char my_char;
HAL_UART_Receive( &huart3, (uint8_t*)&my_char, 1, 10 );
Or you could just make it uint8_t (though you may then get the same warning from C standard string function - which expect char, not uint8_t)
EDIT
2022-06-28 11:05 PM
Declare Rx_Byte as array of uint8_t, not char.
JW
2022-06-29 12:48 AM
Thank you but i will take a char from keyboard. Sorry because of i am new on stm. Why uint8_t ?
2022-06-29 01:26 AM
@MKork.2 "because of i am new on stm. Why uint8_t ?"
It has nothing specifically to do with STM - this is standard C stuff:
You are correct in using char for plain, printable ASCII text - that is what it's for.
However, HAL_UART_Receive() is not restricted to plain text; it handles any arbitrary byte values - hence it uses uint8_t.
You could suppress the warning by casting your char value; eg,
char my_char;
HAL_UART_Receive( &huart3, (uint8_t*)&my_char, 1, 10 );
Or you could just make it uint8_t (though you may then get the same warning from C standard string function - which expect char, not uint8_t)
EDIT
2022-06-29 01:28 AM
Look at the declaration of the HAL_UART_Receive() function. You will see that this argument asks for a pointer to uint8_t and not a pointer to char.
It seems that you are new to STM, but also to the C language. Start with a C training will be very profitable.
2022-06-29 01:42 AM
@Nikita91 "It seems that you are new to STM, but also to the C language. Start with a C training will be very profitable"
+1
Also, it's likely easier to learn the C language on a "normal" platform such as a PC - away from all the added complications & restrictions of small embedded microcontrollers.
Once you've learned the language, then you can move on to applying it to small embedded microcontrollers...
Here's some C learning & reference materials - including a free online textbook:
https://blog.antronics.co.uk/2011/08/08/so-youre-thinking-of-starting-with-c/
2022-06-29 04:52 AM
thank you for answer. Yes i am new to STM and also C but i try to learn.
2022-06-29 05:16 AM
> i try to learn
It is very good.
Good luck and see you later.
2022-06-29 06:40 AM
Thank you Mr.
2022-06-29 07:11 AM
@MKork.2 If your issue is now resolved, please mark the solution: