NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » UART programming (PC side)
April 29, 2010 by Hexorg |
Hey guys, UART is giving me some troubles... I've set up a simple echo on the microcontroller like this:
I have "cat /dev/ttyUSB0" running in one terminal, and I run "echo -e \0377 >> /dev/ttyUSB0" on the other reminal. 0o337 in octal system is 0xff in hexadecimal. However 2 bytes are sent back, cat says: ffa for every "echo -e \0377 >> /dev/ttyUSB0"... why? Also, I'm trying to write a program in c++ that would send sertain patterns to microcontroller. Do I just create an ofstream out ("/dev/ttyUSB", ios::bin | ios::app); and then out << (unsigned int) byte; ? I've tried that and cat reports only every 3rd or 4rth byte. |
---|---|
April 30, 2010 by hevans (NerdKits Staff) |
Hi Hexorg, I think you are seeing those problems because the baudrate isn't set on your terminal. We recommend using minicom for these little tests as it is easier to keep setup correctly with the right settings. It should be in your repositories and instructions on setting it up can be found in our servo squirter tutorial under Serial Port Communications. I'm not very familiar with C++, but I think the problem might also be the baud rate. You might also want to check to make sure there is a way to have flow control turned off, and no parity bits. Humberto |
April 30, 2010 by Hexorg |
Yes, through minicom works great... I'll try to look somewhere more on how to set-up ttys in c++ |
May 01, 2010 by Hexorg |
I've found a great c++ library here. Had a tweak it a little to make it work (#include <string.h> was missing) in Linux, I'm not sure how well will it work in windows, but now it works great :D I've transmit 1152 bytes in about 10 ms :D |
Please log in to post a reply.
Did you know that you can generate hundreds of volts AC from your microcontroller with a little bit of circuitry? Learn more...
|