NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » What's a stream (ala UART)?

February 29, 2012
by jeffspc88mx
jeffspc88mx's Avatar

I understand


but why would I want to use

   uart_putchar(some_char, some_stream)


What's the stream anyway? Do I have to use it? Or can I just call uart_write?

March 01, 2012
by hevans
(NerdKits Staff)

hevans's Avatar

You can certainly just use uart_write if you are writing out simple strings.

The function uart_putchar is there to allow us to use our own uart functions as a stream in C. You are not meant to use it directly.

A stream is a special structure in C that several of the built in io functions use to write to. It is basically an abstraction that lets us treat things you can write characters to in the same way. The most useful thing in our case is that by setting it up as a stream you can then use the printf family of functions to write to the uart, and you can take advantage of format strings.


Post a Reply

Please log in to post a reply.

Did you know that a motor is harder to turn when its terminals are shorted together? Learn more...