COM1 and COM2

James
Hi,

I need to establish serial communication with two devices via COM1 and
COM2. I only need the RX and TX pins for my devices. I read the user manual
and it say that this ports(COM1 and COM2) have 4 pins TX,RX,Vdd, and
ground. The question is do I need to supply 5V to the port or does the port
supply 5v to my device? And by the way, where I can found a tutorial to
make and application on C# or VB to send and receive data using this two
ports (read/send data to the two devices)?


Thanks in advance!!

davef
Can only answer part of this:

The dev board supplies 5V via those pins so that you could power external
circuitry.

See
mini2440_schematic.pdf
on the downloads page.

James
Thanks!

aruangra
Dear James

I bought the RS232 converter from here
http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=120529633660&...
The board pins are configurable. Pin2 can be RX or TX. And Pin3 can be TX
or RX. 

This is my simple program in C to send and receive strings via a RS232
port.

#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>

int main()
{
  int fd;
  struct termios options;
  int n;
  char buff[255];

  /* Open Port */
  fd = open("/dev/ttySAC1", O_RDWR | O_NOCTTY | O_NDELAY);  /* <--- YOUR
PORT */

  if(fd == -1) {
    printf("ERROR Open Serial Port!");
  }
  
  /* Serial Configuration */
  tcgetattr(fd, &options);   // Get Current Config
  cfsetispeed(&options, B9600); // Set Baud Rate
  cfsetospeed(&options, B9600);
  options.c_cflag = (options.c_cflag & ~CSIZE) | CS8;
  options.c_iflag =  IGNBRK;
  options.c_lflag = 0;
  options.c_oflag = 0;
  options.c_cflag |= CLOCAL | CREAD;
  options.c_cc[VMIN] = 1;
  options.c_cc[VTIME] = 5;
  options.c_iflag &= ~(IXON|IXOFF|IXANY);
  options.c_cflag &= ~(PARENB | PARODD);
  /* Save The Configure */
  tcsetattr(fd, TCSANOW, &options);
  /* Flush the input (read) buffer */
  tcflush(fd,TCIOFLUSH);


   write(fd,"YOUR COMMAND STRING HERE",24);

  do{
    n = read(fd,buff,255);   // Read Data From Serial Port
    buff[n] = 0;
    if(n>0)
    {
      printf("%s",buff); // Print Out
    }
  }while(strncmp(buff,"bye",3)); // If user say bye then Exit

  close(fd); // Close Port
  return 0; // End Program
}

James
Thanks a lot Aruangra!!! It will be very useful for me

vikas
Dear James,

 I am also facing issue with COM1 and COM2 i.e I have wrote similar
application but I want COM1 and COM2 should in interrupt mode....instead
of polling mode(as above program)....

if you have any idea plz explore

paolo
Sooner I will try this:
http://qextserialport.sourceforge.net/
I hope this info can be useful to somebody
paolo

paolo
... and also this other link:
http://code.google.com/p/qextserialport/

vikas
thanks paolo these URL's are very usefull please if you have tried for
interrupt based serial communication plz inform me.

vikas
Hello paolo,

  I have tried with example program where I am not getting OK for AT
command, please can you share ur modem code...

Thanks

skip2816
Hi vikas,

try port2 or port 3. Port 1 is bound to the kernel's output. 
To verify this you can connect port 1 to a win pc running DNW. You will see
all kernel's messages.

skip

vikas
hello skip2816,

 I have tried for port2 and even port3 also but no change..

Stuck
Hi i've tried to execute the above code but it says 
/dec/ttySAC1 : No such file or diresctory.

i have checked /dev and ttySAC1 is there..
any hint?

MikeB
Stuck: are you executing as root or another user.

Stuck
i tried being both but in vain.I'm trying to execute the code on my host ie
x86 with ubuntu 9.04.i change the path to "/dev/ttyUSB0" as i have a PL2303
serial converter.I compile the above code fine.my main concern is why on
executing the code(on my host) i find the error /dev/ttyUSB0 :No such file
or directory, when i can see it in /dev. i can use my PL2303 converter with
the mini2440 .i even tried doing
chmod 777 /dev/ttyUSB0
also 
chmod 777 /dev/ttyS0 (thinking if it opens with the code)
Even executed the code being su.
guys do we need to like create nodes or somethingg before executing the
code?I tried the code on mini2440 with path "/dev/ttySAC1" and get the same
error!! help?

Janusz
Hi,

I read manual but I could not find any information. Can you tell me what is
the voltage level of the COM2 ? I tried to connect microprocessor (PIC) to
the friendlyARM through RS but there is data on the port. (It means if I
write "cat /dev/ttySAC1" I do not see anything, and I know that
microprocessor send something to the RS232). 

Where is the problem ?



p.s. Stuck. Under linux you can open tty as a normal file and you do not
need this code above :)

kate
Hi Aruangra,

I have tried with your code. It is compiled without any error but when i am
running it on my ARM board, it shows the message-"SERIAL device temporarily
unavailable". Please guide me what to do.

Dhoni
when i tried to open the device using:
  fd = open("/dev/ttySAC1", O_RDWR | O_NOCTTY | O_NDELAY);
it didn't open, it was showing the similar message that the serial device
is temporarily unavailable. later i changed the way i opened the device
like:
  fd = open("/dev/ttySAC1", O_RDWR);
in this case the device is opened, but here it stuck at read operation.
Tell me how can i resolve the issue.

Yuvraj
hi everyone,
    i want to know what is the default setting of serial port for read and
write operations. Can anybody tell me. I actually, want to use COM2 for
RS485 protocol. Please help me out quickly.

MikeB
I did a fair bit of searching. Are the TTL serial lines 3.3v or 5v. There
is a GND,5V and RX and TX. Are the RX and TX 5V or 3.3V ?

The Code: 
#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>

int main()
{
  int fd;
  struct termios options;
  int n;
  char buff[15]="";
        
  /* Open Port */
  fd = open("/dev/ttySAC1", O_RDWR | O_NOCTTY | O_NDELAY);  /* <--- YOUR
PORT */

        
  if(fd == -1) {
                  printf("ERROR Open Serial Port!");
                }
              

  /* Serial Configuration */
  tcgetattr(fd, &options);   // Get Current Config
  cfsetispeed(&options, B9600); // Set Baud Rate
  cfsetospeed(&options, B9600);
  options.c_cflag = (options.c_cflag & ~CSIZE) | CS8;
  options.c_iflag =  IGNBRK;
  options.c_lflag = 0;
  options.c_oflag = 0;
  options.c_cflag |= CLOCAL | CREAD;
  options.c_cc[VMIN] = 1;
  options.c_cc[VTIME] = 5;
  options.c_iflag &= ~(IXON|IXOFF|IXANY);
  options.c_cflag &= ~(PARENB | PARODD);

  /* Save The Configure */
  tcsetattr(fd, TCSANOW, &options);

  /* Flush the input (read) buffer */
tcflush(fd,TCIOFLUSH);
printf ("\ntest point 1\n");                       
write(fd,"R",4);
printf ("\ntest point 2\n");    
 /* Flush the input (read) buffer */
printf ("\ntest point 3\n");  
tcflush(fd,TCIOFLUSH);
printf ("\ntest point 4\n");  
write(fd,"S",4);
sleep(4);
printf ("\ntest point 5\n");
read(fd,buff,10);   // Read Data From Serial Port
printf ("\ntest point 6\n : %s : \n",buff);   // Print Out

close(fd); // Close Port
  return 0; // End Program
}


To the PC the Mini Sends:
R
S

When I use the pc to answer it displays what ever i can type in 4 seconds
on the conn.

The device :
http://www.embeddeddatasystems.com/HA7S--ASCII-TTL-1-Wire-Host-Adapter-S...

The HA7S Answers correctly when connected to the pc but not the mini.

In my mind connecting the 5v GND and RX TX should be a no-brainer and the
whole thing should work great. I have tried running the ha7s on 3.3v from
the IO header but to no avail.

Any suggestions?

davef
The RX and TX lines should be about 3.3V.  This may not be enough to tell
the PC that you have data. 

Can you check that you actually have data coming out the TX port when you
send something from the mini2440? Oscilloscope?

In the HA7S datasheet what does it say for the minimum logic levels for
it's input?  Maybe, that is not enough for the TX line to register a change
on the USART in the PC.

davef
correction:  . . . for the HA7S to recognise a change on COMMx in the
mini2440

bergenm
Thanks for the response. no o-scope available.. :[ but i am using level
shifter to go from pc to ha7s and mini2440 com1 to pc. i have even tried
hooking two level shifters between them. mini2440 to 3.3v and ha7s to 5v.
I'll try changing com port to /dev/ttysac2

Akash
Hi I want to send data through COM1 and Receive through COM2 in WINCE in
same board is it possible? 

Please help me out

mgdaubo
Hi, follow aruangra and MikeB 's codes, i compile my own application, i use
ttySAC1, the micro2440 can send string to PC host ok, but it cannot receive
anything :(
I try to change VMIN and VTIME to 0, but: 
   n = read(fd,buf,2);
   buf[n] = 0;
   printf("%s",buf); // Print Out
still not print out anything.

And I also try "fcntl(fd, F_SETFL, FNDELAY);" and set VMIN and VTIME to 0
to get read function return immediately, but it seem takes about 0.1s to
return, and it returns no string :(

any idea for this, please help me out, thanks.

mgdaubo
Oh I found that my own application can receive char from host PC, sure. But
it cannot print out the terminal window by "printf" function. I don't know
why.

To print out the string received, we should open and write to /dev/tty.

I wonder that after the function to open /dev/ttySAC1 and init it, I can
printf(...) something; then enter the loop while(1), I cannot use printf
???

shaco
dear all, i tried aruangra code's. it's work for me. but when i try to send
string from my pc to mini244 (for example if i sent "good evening"), then i
got:
good eve
ning

what should i do to receive "good evening" at once?

ramarao
hi,
   my com2 port is unable to detect my modem while it is working in com1.
 when the modem is connected in com2 and queried the modem i am getting
indication on my modem where i am getting a responce like "no modem is
detected"

davef
Not sure if this helps, but to enable (I think Com2 for serial comms) in
your start-up script (/etc/init.d/rcS or profile.environment) or manually
try:

chmod 666 /dev/ttySAC1

junk
hi guys !! i have a problem  . I need to read a sensor for COM0 COM1 and
the output of them  is for  COM2 can  anyone help me?


and sorr for mY english XD

davef
What is the problem?  Writing the code? Setting up the COM ports?

junk
yes  i need write  the code...or a example  how to perform the
configuration and code in ttyCSA0 ....help me  in  something  plz

beginner
How can I check the amount of received bytes in the buffer without reading
the buffer ?
Is there any rx_counter or something ?
it's important because if you don't know how many bytes u have received in
your buffer you try to read for more bytes then there actually are, the
program stucks on read operation trying to read bytes that are not received
yet...
and one more thing, I cannot close the port by close(fd) my compiler gives
an "error: no matching function for call to 'MainWindow::close(int&)'"
I'm using Pengutronix's BSP and Toolchain.

any idea?

Meena Tikhe
is friendly arm can be directly used with max232 5v supply. in this case rx
will be 5v n not 3.3v.
and will max232 convert 3.3v tx to rs232 level?
any idea?

gitanjali sayambar
is friendly arm can be directly used with max232 5v supply. in this case rx
will be 5v n not 3.3v.
and will max232 convert 3.3v tx to rs232 level?
any idea?

davef
Would a variant of the MAX232 running off 3V3 do the trick?

http://www.maximintegrated.com/datasheet/index.mvp/id/1068