Skip to main content
VEnes.1
Visitor II
Aug 12, 2022 8:39 AM UTC
Question

Newline not working in string

I use stm32cubeIDE

my code:

sprintf( mesaj, "xaccl = %3.3f /n ", xaccl );
HAL_UART_Transmit( &huart6, mesaj, sizeof(mesaj), HAL_MAX_DELAY );

how I can fix /n terminal problem?

thanks for answers

 

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
Aug 12, 2022 8:48 AM UTC

Use the proper escape character, ie \n

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
Aug 12, 2022 9:31 AM UTC

Might also point out that sprintf returns the length of the generated string, and sizeof() isn't suitable for strings.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Bob S
Super User
Aug 12, 2022 5:48 PM UTC

And use snprintf() instead of sprintf(). Friends don't let friends use sprintf().