This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

why printf in embedded C?

i am using keil uvision 2.
plss tell me why we use printf in embedded c?
if its 4 debugging,HOW?
if its 4 serial commn/transmit characters to serial port,HOW?
plsssssssssssssss some1 help.........i searched everywere but i dint get answer..

  • We use it because we (or in this case you) have decided that it is better to use printf() than to use any other method for solving something.

    Different embedded projects has different needs. So what functions to use (or not use) is something you decide for each and every project. And also, what your needs are for debugging. Or if the device even have any interface that may receive the data from printf().

    So when giving the answer to the school assignment, you will yourself have to come up with advantages and disadvantages with printf() - and examples where it is good to use printf() and examples where it should be avoided.

  • This sounds too much like a homework question. Still, the answer is "why not?"

  • why we use printf in embedded c?
    I, personally, do not

    Erik

  • Much the same reason as printf in any other kind of 'C' !

  • NO.......
    my question is....
    In NORMAL c for non-embedded application we use printf to print something on screnn(monitor).
    Usually an embedded system doesnt hav any monitor or display.
    THEN WHY this printf in embedded C.
    People DO use printf in embedded C ,i know, but WHY? FOR WHAT PURPOSE? AND HOW?
    If i write, printf("dhaneesh");//target: 8051
    what will happen?
    Will it pass each character to serial port(and to hyperterminal if connect 8051 target system to a pc throug rs232)?
    Will it display on Serial Window?

    WHY..........WHY......WHY......?
    PLSSSSSSSSSSSSSSSS HELP ME.............

  • In a PC, printf() prints to the command line console.

    In an embedded project, the compiler kit is delivered with a library with the "front end" of printf(). You as developer will then have to look a the "back end" - where the characters will go if you do use printf().

    You might decide to send the characters on a UART connected to a MAX232 or similar, so you could connect a PC directly for viewing the data.

    Or you might decide to route the characters to an embedded module (such as a GSM modem) connected directly to the processor.

    Or you might decide to route the characters through a SPI interface.

    Or you might decide to route the characters to a large ring-buffer implemented in an EEPROM memory, to allow you to allow you to later connect to a device out in the field and pick up any error messages printed to this buffer during the months the device was working stand-alone somewhere.

    Or you might decide to not route the characters anywhere at all, in which case it would be pointless to call printf() at all.

    In _some_ environments, the debugger/processor may implement a virtual serial port that allows an embedded device without any physical serial ports to print data directly to a log window in the debugger.

    But why don't you put down some own time on this school assignment? Do you feel that your own time is much to valuable for doing own work - that you are of special "pure" blood that makes it your birthright to have other people serve you with all the information you need so you yourself can reserve your time for rest and relaxation?

  • The more time you spend making your question clear and complete, the more likely you are to get good replies!

    "In NORMAL c for non-embedded application we use printf to print something on screnn (monitor)"

    No, that's not exactly true, is it?

    The actual definition is that printf writes to stdout - and it's stdout that is normally routed to the screen.

    "People DO use printf in embedded C ,i know"

    How do you know?

    "but WHY?"

    This has already been answered: people use printf because it is appropriate to the task at hand - specifically, for making formatted text output.

    There are plenty of examples on this very site that use printf - so take a look at them!

    "If i write, printf("dhaneesh");//target: 8051
    what will happen?"

    For implementation-specific details, you must always read the Manual for the particular tools in question!

    The Keil C51 Manual clearly explains its implementation of printf

    "Will it pass each character to serial port"

    Please read the manual!

    "Will it display on Serial Window?"

    Please read the manual!

  • Hi Dhaneesh,

    Take a peek at the following link:

    members.iinet.net.au/.../Sio_poll_0.6.php

    The detailed module will readily enable you to use high-level C library functions like printf(), scanf(), etc., with your RS232 serial hardware.

    It was created specifically to serve people with your very question, Dhaneesh.

    Regards,
    Murray R. Van Luyn.