RS-232 Port Break Charator Caused

Posted on 1997-09-04
Last Modified: 2013-12-26
Hi, All,

I am writing a short program which interfaces to the little Motorola 68hc11 processor.  I need to detect break charators (RxD stucked to constant zero) and cause an interrupt signal to the main process.

According to man termio:

   If IGNBRK is set, the break condition is ignored.  Therefore the break
      condition cannot be read by any process.  If IGNBRK is clear and
      BRKINT is set, the break condition flushes both the input and output
      queues and, if the terminal is the controlling terminal of a
      foreground process group, the break condition generates a single
      SIGINT signal to that foreground process group.  If neither IGNBRK nor
      BRKINT is set, a break condition is read as a single \0 character, or

 I put the statement:
      t_ptr.c_iflag = BRKINT
in the following code to enable the interrupt.  

I also use a scope to make sure I indeed put a constant zero (+12v) onto the RxD line.  The problem I am having is that no matter what I do, the break charactor on the RxD line will _never_ cause an interrupt.  Just to verify the interrupt is still working, I use the alarm() function to cause an interrupt every 5 second.  The alarm() function works.  Secondly, if I ran the following program, I can make the SIGINT signal triggered by hitting ctlr-C.  Second ctlr-C will terminate the execution.

I am using a Ultrasparc and runing SunOS 5.5.1.  

Please help and thanks.

Jian Zhang
DSC Communications Corp.
Petaluma, California

Here is the source code:

------------------cut here------------------




unsigned char  bin_wt [2048];
int        fd;

void alarm_hdlr();
void sig_handlr();

main(int argc, char * argv[]) {

  const  baud_rate = B1800;
  const sync_char = 0xff;

  unsigned char in_char;
  int    i, j;

  int    n, wrt_n, rd_n;

  FILE*  file_ptr;

  struct termios t_ptr;

  char* str_line;
  char* str_load;
  char* a_str;

  unsigned char  bin_rd [2048];
  unsigned int srec_len;

  str_line   = (char*)malloc (1024);
  str_load   = (char*)malloc (3000);
  a_str      = (char*)malloc (3000);

  bin_wt [0] = sync_char;
  fd = open("/dev/ttyb", O_RDWR);

  //t_ptr.c_iflag = BRKINT | INPCK;
  t_ptr.c_iflag = BRKINT;
  //t_ptr.c_iflag = PARMRK;
  t_ptr.c_oflag = 0;
  t_ptr.c_cflag = CS8 | CREAD | CLOCAL | CSTOPB;
  t_ptr.c_lflag = 0;
  t_ptr.c_cc[VTIME] = t_ptr.c_cc[VMIN] = 0;

  cfsetispeed(&t_ptr, baud_rate);
  cfsetospeed(&t_ptr, baud_rate);
  tcsetattr(fd, TCSANOW, &t_ptr);

  if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
    printf ("enable signal\n");
    signal(SIGINT, sig_handlr);

  signal(SIGALRM, alarm_hdlr);

  while (1) {
    if (read(fd, &in_char, 1)) {
      printf ("received char = %x\n", in_char);


  exit (0);

void alarm_hdlr() {
  signal(SIGALRM,  alarm_hdlr);
  printf ("inside alarm_hdlr\n");

void sig_handlr() {
  printf ("inside sig_handlr().\n");
  write(fd, bin_wt, 1);

Question by:jian_zhang
  • 2

Author Comment

ID: 1294777
Edited text of question

Accepted Solution

hotlava earned 200 total points
ID: 1294778
There seem to be several things missing from the code.  When changing ioctl flags, one would normally read the existing flags, and just set or clear the particular flag that they aare interested in.  This means that you do not have to know what all of the IO flags do, but just the ones you are interested in.  So my first recommendation is to change the flag setting code to a "get flags", clear IGNBRK and set BRKINT, "set flags".  And my second recommendation is to ensure that you are the controlling terminal of a foreground process group, like the man page says.  To do this is think you would use setpgrp - although I may be wrong here so you'll have to do some reading, but even so, the code you posted appears to make no effort to create a process group, so may be another possible cause of your problems.

Author Comment

ID: 1294779
Hi, hotlava and other experts,

The above answer did help me to get an interrupt (signal) when a break char is received.  But the interrupt only occurs when the RxD line changes from low->high.  It seams to me that the COM port is waiting for a valid '0x00' with valid stop bit appears on RxD line when it generates the interrupt.  My application requires my code detects a high->low transition on RxD instead.  Any comment on this?

Thanks again.

Jian Zhang
DSC Communications

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 92
matchUp  challenge 6 65
firstChar challenge 13 115
Is there a simple front-end menu system. 9 90
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question