Page 1 of 1

How to send data to the serial console

Posted: Tue Apr 24, 2018 9:22 pm
by PawelJalocha
What is the best/easiest/quickest method of sending data to the serial console ?
I mean the most direct method, with least overhead and no data manipulation.
I use putchar() for now but I find it does NL to CR+NL conversion and I would like to avoid such conversion if possible.

Re: How to send data to the serial console

Posted: Thu Apr 26, 2018 5:14 am
by kolban
Would printf() not be sufficient? If you need to absolutely minimize latency and simply send a byte ... then the serial API would be the lowest level ...

search for:

uart_write_bytes()

as the ESP-IDF function to use.

Re: How to send data to the serial console

Posted: Thu Apr 26, 2018 5:41 pm
by PawelJalocha
Thank you, my main objective right now is to avoid the NL to CR+NL translation and keep the call as elementary as possible. Involving printf() for every character printed would clearly be too much overhead.

Thus I can assume the UART for the console is open and so I can just write to it. Can I read it too ?
What kind of buffering shall I expect in such case ?

Re: How to send data to the serial console

Posted: Fri Apr 27, 2018 2:46 pm
by kolban
Howdy,
Have a good read at this documentation page:

http://esp-idf.readthedocs.io/en/latest ... /uart.html

I think its quite well written and comprehensive. There is a lot there so take your time and read it a few times. If you have questions, post back.

If we were chatting, I'd probably clarify the notion of the "serial console". The ESP32 uses a serial port (also called UART) to read and write data into it. This is what is used by esptool when you flash the device. When you run an ESP32, the application contained within it "just runs" ... however, convention is that during development, we log messages to the UART which can then be read by an external terminal application (or make monitor in ESP-IDF). I'd suggest to stop thinking of the ESP32 as having a "console" but instead think of the ESP32 as having a UART serial port which can "act" as a console.

Yes you can both read and write to the serial port.

See also:

http://esp-idf.readthedocs.io/en/latest ... m/log.html
http://esp-idf.readthedocs.io/en/latest ... nsole.html

Re: How to send data to the serial console

Posted: Sat Apr 28, 2018 12:43 am
by PawelJalocha
Thank you again,

In my application, all works fine, when I use putchar() and the base call to send characters to the console.
But when I try to use UART library and I call uart_write_bytes(UART_NUM_0, ) then I receive stream of errors like:

uart: uart_write_bytes(1073): uart driver error

thus what am I doing wrong ?

Pawel.

Re: How to send data to the serial console

Posted: Sat Apr 28, 2018 6:58 pm
by kolban
Did you first call uart_driver_install() to install the driver?

See:

http://esp-idf.readthedocs.io/en/latest ... stallation

Re: How to send data to the serial console

Posted: Sat Apr 28, 2018 10:49 pm
by PawelJalocha
No, but I am writing to the console UART, which is already setup and open, correct ?

I am communicating with the GPS UART and it all works fine, I set it up, etc.
But the console UART is already setup by the system I understand.