Loading ...
Sorry, an error occurred while loading the content.
 

Re: Set serial port and send data in NSLU2--noob question

Expand Messages
  • Phil Endecott
    ... It s the same as any other Linux (or Unix) system. From the command-line, use stty: # stty -F /dev/ttyS0 9600 From C, use cfsetspeed(). You should do this
    Message 1 of 5 , Dec 11, 2007
      duy_pham wrote:
      > But I don't know how to set the serial port of NSLU2 to a lower baud-rate
      > (ie 9600 baud rate) to match the microcontroller baud-rate and how to send
      > data through serial port.

      It's the same as any other Linux (or Unix) system.

      From the command-line, use stty:

      # stty -F /dev/ttyS0 9600

      From C, use cfsetspeed(). You should do this in a read-modify-write
      block so that other terminal attributes are unchanged:

      struct termios settings;
      int rc = tcgetattr(fd, &settings);
      if (rc<0) {
      ....error....
      }
      cfmakeraw(&settings); // You probably want this if it's not a
      human at the other end
      rc = cfsetspeed(&settings,baudrate);
      if (rc!=0) {
      ....error....
      }
      rc = tcsetattr(fd, TCSANOW, &settings);
      if (rc<0) {
      ....error....
      }

      The man pages for stty and cfsetspeed describe all this in detail.

      > I've just try to use this simple C program, but it didn't work.

      Well, it doesn't make any effort to set the baud rate, so it's not
      going to work.


      As others have pointed out, you need to disable the console getty that
      is running on /dev/ttyS0. Do this by editing /etc/inittab and then
      rebooting. Note that although this will get rid of the login prompt,
      you'll still get the kernel's bootup output and before that the
      bootloader; changing that is more difficult. Luckily, your
      microcontroller won't see that - except perhaps for some random garbage
      characters - if it's configured for a different baud rate.

      Good luck,

      Phil.
    • John
      To set baud from the Linux command-line, you can use stty or setserial. From python on a NSLU2, I have done serial port I/O, including setting baud rates, with
      Message 2 of 5 , Dec 11, 2007
        To set baud from the Linux command-line, you can use stty or
        setserial. From python on a NSLU2, I have done serial port I/O,
        including setting baud rates, with the pyserial module. To set the
        BAUD rate from within C, you need to look in Unix C language docs.

        The slug treats the built-in serial port as a user terminal.
        If you have something active connected to the port during boot, you
        may have problems.

        John
      Your message has been successfully submitted and would be delivered to recipients shortly.