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.

Support Forum » receiving char from computer using usb to serial cable

February 25, 2010
by sharadgupta7
sharadgupta7's Avatar


I could run the temperature sensor example succesfully i.e. i saw the temperature printed on my putty session window.

Now i wanted to do reverse i.e. i want to send data from my putty session window to my program running on the microcontroller and displaying it on the LCD. Unfortunately, this didnt work. It gets stuck at uart_read() function call.

here is my sample program.

int main() {
  FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);

  // init serial port
  FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
  stdin = stdout = &uart_stream;
  lcd_write_string(PSTR("  Welcome...  "));

  char tc;
  while(1) {

// Wait for a character to be sent to the serial port.
tc = uart_read();
    fprintf_P(&lcd_stream, PSTR("%c"), tc);
  return 0;

I tried uart_write() instead of uart_read() and it worked i.e. it sent the hardcoded character to my putty session window.

Please help...


February 25, 2010
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi sharadgupta7,

I don't see anything immedately wrong with your code example. Here are three quick things to try:

First, verify that your Putty settings are correct (115200 baud, 8 data bits, no parity).

Second, move both the green and yellow wires of the serial cable to an otherwise-empty breadboard row. This connects the transmit directly to the receive, so you can do a "loopback test". Verify that whatever you type into the Putty window shows up. Now, remove one of the wires, and try again, and the echoing should stop. Is this the case?

Third, replace your fprintf_P call with "lcd_write_data(tc);" -- just in case some weird compiler or other issue is getting in the way.

Let us know what happens!


February 25, 2010
by sharadgupta7
sharadgupta7's Avatar

Hi Mike,

1) yes, its exactly my putty settings (also no flow control and 1 stop bits) 2) I moved the two wires in the same row and still no echo on the putty window. 3) fprintf replaced with lcd_write_data and same result.

Please note that send to this serial port is working fine as i could see the temperature being printed on the putty terminal. I also treid uart_write which also worked.

One more experiment which i did was to install the prolific usb to serial adapter on a windows xp machine . I shorted the tx and rx pins but putty did not echo the chars back. Then i used another serial cable and plugged it in the genuine serial port of this machine and shorted the two pins and i could see the echo...

All this makes me belive that it is working fine in one direction i.e. from microcontroller to computer but the reverse direction is a problem..

Please guide as i am stuck...

Thanks very much for your help.

February 26, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi sharadgupta7,

It certainly sounds like data from the computer isn't getting back to the MCU, but if that true then you would not be able to program your chip any more. Are you able to program the chip reliably?


February 26, 2010
by sharadgupta7
sharadgupta7's Avatar

hello Humberto,

Ohh I see, I am perfectly able to program my chip that means the cable is working fine in both directions..then what could be problem...

Thanks, Sharad

February 26, 2010
by sharadgupta7
sharadgupta7's Avatar

Hey, you know what.. i wrote my own serial port communication program using mscommctrl and guess what it worked... But with putty, it didnt work.....My putty version is 0.60.. So putty still remains a mystry to me but atleast i can move forward....

The other experience which i would like to share is that i used another prolific usb to serial adapter which i purchased for some other project. My understanding was that both nerdkit's cable and my cable should work interchangeably... Right??? But to my surprise, when i used my cable to program the chip, it gave me an error everytime towards the end of writing process.... But when i used nerdkits cable, everything was allright as always... I am little confused about it..Could you please shed some light on it...

Many Thanks, Sharad Gupta

Post a Reply

Please log in to post a reply.

Did you know that multiple microcontrollers can communicate with each other? Learn more...