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 » Trouble with uart

November 30, 2010
by gusr205
gusr205's Avatar

I used the simple program example to test printf_P and scanf_P via uart to my laptop.

main()
{
double z = 0.0;
uart_init();
FILE uart_stream= FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
stdin = stdout = &uart_stream;
printf_P(PSTR("\r\nHow Old Are You?"));
scanf_P(PSTR("%d"), &z);
printf_P(PSTR("lf"), &z);
return 0;
}

I am using Windows hyper terminal. When I run the program I see How Old Are You? on the screen and then the program seems to be waiting for an input to scanf_P from the keyboard but I can't enter data from the computer keyboard. It seems like communications is not not bi-directional however I can program from the computer. Can someone tell me what I am doing wrong? Thank you!
December 01, 2010
by exussum
exussum's Avatar

Hit enter, Its being types on the other side. There is a setting i think on Hyper Terminal to see whats being typed but im not 100% sure.

Also you will probably need to have your code accept a string not a double.

December 01, 2010
by exussum
exussum's Avatar

Solution: If the remote computer is not configured to echo user input, you can configure your computer to do so with the following steps:

  1. On the HyperTerminal File menu, click Properties.

  2. On the Settings tab, click ASCII Setup.

  3. Check the Echo typed characters locally box.

December 01, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi gusr205,

Like exussm mentioned terminal programs are not always configured to echo the input you type into the keyboard to the screen. They however almost always send your keyboard input to out the serial port. Looking at your code it looks like you have your code set up to get input from the serial port, then echo that input back out to terminal. And that should work. It looks like your code is expecting a number. Is that what you are typing in the keyboard? Also remember that you need to press enter after you enter a number for the scanf function to read it in.

Humberto

Post a Reply

Please log in to post a reply.

Did you know that many systems in nature can be described by a first order response? Learn more...