ESP8266 SDK: os_printf() prints garbage, uart_init() doesn’t work…
by kacang bawang
Espressif SDK provides a function os_printf()
for printing to the debug uart. However, when used out of the box it prints garbage. What gives?
Consider a default project with the following in user_main.c.
1 2 3 |
void user_init(void) { os_printf("hello world\n"); } |
Compile, run, what do you see? That’s right – garbage. Well, it’s not really garbage, it’s actually outputting “hello world” at the default (non standard) baud rate. Ok, easy enough – we’ll just set the baud rate using uart_init()
function from the SDK! Oh, wait… that function is not defined in any header that comes with the SDK… Paging Espressif, please pick up the white courtesy telephone!
That’s ok, there’s an easier way – we will use uart_div_modify()
to achieve the same result. Change the hello world to this and try again:
1 2 3 4 5 |
void user_init(void) { //0 refers to uart0 uart_div_modify(0, UART_CLK_FREQ / 115200); os_printf("hello world\n"); } |
Much better! Hat tip to unfoundbug
at this reddit thread.
Thanks a lot for the Help i was getting garbage in serial monitor and this function solved it so charmingly! Hurray!
glad to help!
Thank you, that helped me out.