Saturday, August 18, 2012

Using screen to send serial communication rs232 at 9600 baud rate

A few weeks ago, I found a great method for sending and receiving serial data.

When I did the UART lab in school we used cute com in order to send and receive a byte of information.  for example, if I entered "Hello" in to the cute com, it would send something through the usb.  The usb would enter the nexus 3 spartan6 board.  some magic would happen and then it would send back the message through the usb and into the pc.  then cutecom would show"Hello" again.

ie "HelloHello"

The problem was that I was using a mac and at the time I had no idea how to do something like cute com.  I know about the existence of mini com but I did not want to download it.  In the back of my mind I thought that this would be a great opportunity for me to make my own "mini com", but the question what how?  I had many fruitless googling until I stumbled upon "screen".

Apparently "screen" could be used instead of "mini com" .  This was great news!  I'm not going to go into the technical details of how I interfaced my fpga with my mac book pro (10.7) because I had covered that in a past post.

Question....How to use screen?  It isn't hard.  After you plug it in you type this into the terminal without the quotes.
"screen <usbserial_com> <baud_rate>"

in my case the usbserial_com was "/dev/tty.usbserial-A700h2To"
and my baud rate "9600"

ie.
"screen /dev/tty.usbserial-A700h2To 9600"

How do I test if it works?
I pulled out one of my old UARTio labs from the past.  All it did was receive and transmit.  It was an unfinished project where I was suppose to add keyboard functionality to it, but I never got around to it. Luckly, my procrastination turned out for the better, cause now I could simply compile what I had without having to change anything.

I compiled it, and programmed the fpga. flipped the switches.
I ran the screen command that I mentioned above.

at first it looked like an empty terminal.

I typed "a" and I recieved an "a".  I turned off the fpga and typed "a" again. nothing happened.
So the uartio was working correctly.  I type something in, it goes to the fpga then pops back to the terminal.  SWEET.

ok, what about a more realistic solution?  eventually I would write a program that would read in an image (i.e. bmp)  and send some info through the usb and write somewhere on the   fpga memory.

So at first i thought I could write a c++ program that would run "screen"
But as it turns out, most programs wouldn't do that.

Eventually I found this neat site from arduino.  It was meant for serial compunication with an arduino, but oh well, same difference.
http://todbot.com/arduino/host/arduino-serial/arduino-serial.c

Here is a link to more languages.
http://www.arduino.cc/playground/Main/InterfacingWithSoftware


As of now, I'm using the  "C" version.  Reason being that it is useful for osx/windows/linux.
The only problem is that I haven't quite figured out how it works.  After tracing it with my eyes, I tried distilling the most essential parts so that I could make my own dedicated program.  I failed.  for now, But eventually I'll get it.

So then I tried using the Arduino C code as is and it actually worked.
ie ./a.out -b 9600 -p /dev/tty.usbserial-A700h2To -s 3; //actually sends the ascii version of 3.

Oh yeah, the data I send to the fpga shows up on the 8 led's so I can verify what is being sent.

TMR I will go through the program more carefully and trace its path.  I WILL find out how to write my own.

No comments:

Post a Comment