Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Chuck Messenger <chuckm@rochester.rr.com>
To: linux-serial@vger.kernel.org
Subject: Trouble reading from my serial device (a microcontroller)
Date: Thu, 20 Nov 2003 14:22:52 -0500	[thread overview]
Message-ID: <bpj3mo$6th$1@sea.gmane.org> (raw)

I'm unable to read from a serial device under Linux (Mandrake 9.1, 
2.4.21-0.13mdk kernel), but the device works find in Windows.  I'm 
hoping someone can offer me suggestions.

My device is a Basic Stamp microcontroller, which I've programmed to 
spit out a certain byte continuously -- 0x40 -- at 38400 baud,n,8,1. The 
device loops RTS back to DSR (i.e. it connects pins 6 and 7 of the 9-pin 
serial connector -- DSR and RTS).  Other than that, only Rx and Tx are 
connected (and ground, of course).

I know the hardware works (both controller and PC), because I can boot 
Win2k on the same machine and run a short program I wrote which 
continuously dumps to the console whatever comes in.

Also, I know that things are _basically_ configured right, in my Linux 
boot, since I can run "statserial /dev/tts/0", which shows, in real 
time, the status of the DSR line.  When I unplug from my device, DSR 
goes low; when I plug it back in, DSR goes high.

I tried writing a simple port-dumping program on Linux, based on Peter 
Baumann's sample in his Serial Programming Howto:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>

#define BAUDRATE B38400
#define MODEMDEVICE "/dev/tts/0"
#define _POSIX_SOURCE 1 /* POSIX compliant source */

int
main()
{
     int fd,c, res;
     struct termios oldtio,newtio;

     fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );

     if (fd < 0) {
         perror(MODEMDEVICE);
         exit(-1);
     }

     tcgetattr(fd, &oldtio); /* save current port settings */

     memset(&newtio, 0, sizeof(newtio));

     newtio.c_cflag = BAUDRATE | /*CRTSCTS |*/ CS8 | CLOCAL | CREAD;
     newtio.c_iflag = IGNPAR   // ignore parity errors
                    | IGNBRK;  // ignore BREAK characters
     newtio.c_oflag = 0;

     /* set input mode (non-canonical, no echo,...) */

     newtio.c_lflag = 0;

     newtio.c_cc[VTIME]    = 0;   /* inter-character timer unused */
     newtio.c_cc[VMIN]     = 1;   /* blocking read until 1 chars received */

     tcflush(fd, TCIFLUSH);       // Flush an data received by not read
     tcsetattr(fd,TCSANOW,&newtio);

     while (1) {       /* loop for input */
         char buf[1];
         res = read(fd,buf,1);   /* returns after 1 chars have been input */
         printf("%02x ", buf[0]);
         fflush(stdout);
     }

     tcsetattr(fd,TCSANOW,&oldtio);

     return 0;
}


However, the program fails to read any bytes -- it hangs at the read().

I've tried running serlook, but that, too, failed to see any bytes.

Any suggestions?

I've tried 9600 baud instead of 38400 -- still no luck (although it 
works under Win2k).

Poking around, I've seen mention of the DCD control line -- could that 
be the problem (i.e. does the Linux serial driver require it, somehow? 
I don't have it hooked up.)


     - Chuck Messenger



             reply	other threads:[~2003-11-20 19:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-20 19:22 Chuck Messenger [this message]
2003-11-20 21:07 ` Trouble reading from my serial device (a microcontroller) Chuck Messenger
  -- strict thread matches above, loose matches on Subject: below --
2003-11-20 20:42 Ed Vance

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='bpj3mo$6th$1@sea.gmane.org' \
    --to=chuckm@rochester.rr.com \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox