Sending a break signal using 16F877 usart

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
Tom Stefanou
Posts: 32
Joined: Thu Nov 15, 2012 7:21 am
Has thanked: 7 times
Been thanked: 7 times
Contact:

Sending a break signal using 16F877 usart

Post by Tom Stefanou »

Hello everyone!
I am trying to generate a break signal using 16F877's usart.
Actually the same break signal that e.g putty terminal software generates.
I know it is not a character but a line condition.
I have read about it but i am not sure how to create it.
Any help would be appreciated.
Thank you in advance.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by medelec35 »

Hi Tom,
When I want a line break I send:
line break.png
(51.57 KiB) Downloaded 6519 times
Followed by char 10

Char 13 = Carriage return
Char 10 = Line Feed

Not 100% sure if that's what your after or not?

Martin
Martin

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Enamul »

Transmitting a BREAK Signal
A BREAK signal is a communications signal that allows two communications devices to transmit a "break" in the transmission line. This article discusses how a communications program implemented using the Microsoft Windows Communications API (Comm API) can send a BREAK signal.
A BREAK signal, sometimes mistakenly referred to as a BREAK character, is any SPACE condition on the communication line that lasts longer than a character and its framing bits.
Comm API contains two functions, SetCommBreak() and ClearCommBreak(), to assist in sending a BREAK signal. Merely calling these two functions in sequence will not cause a BREAK signal to be sent. Use one of the two methods described below to transmit the BREAK signal:
Method 1
The International Consultative Committee for Telephone and Telegraph (CCITT) modem recommendations require a break signal to be at least "2m+3" bits long, where "m" is the nominal number of bit times in an asynchronous character, usually 10; this means that the minimum break time is 23 bits, with no maximum specified. Usually, much more than the minimum is sent, such as 100 or 200 milliseconds (that is, hundreds of bit times at high data rates). The timer resolution in a PC is sufficient for sending such "long" BREAK signals, but not sufficient to send exactly 23 bit times.

An application can call SetCommBreak() to initiate the BREAK signal. Use SetTimer() to set a timer and wait for the recommended duration, and then call ClearCommBreak() to terminate the BREAK signal.

NOTE: If an application sends some data and subsequently calls SetCommBreak() before that data has had a chance to make its way through the transmit first in, first out algorithm (FIFO), the data will actually be overwritten by the SetCommBreak() and not get onto the line. To prevent such corruption, it is recommended that you pause for a while before the SetCommBreak().

Method 2
An alternative means of sending a BREAK signal of shorter duration is to temporarily change the data rate in the UART to half or 1/4 of the actual line speed and then send a single NULL byte. This is more precise than using SetCommBreak() and ClearCommBreak(), but it has the disadvantage of corrupting received data during the time the BREAK signal is being sent (because the received data rate is wrong during that time). An application can change the date rate in the UART with a call to SetCommState(). The DCB structure passed to SetCommState() specifies the new data rate.
The whole story I posted to give an idea & I think method two can be easily implemented in flowcode for PIC USART
Enamul
University of Nottingham
enamul4mm@gmail.com

Tom Stefanou
Posts: 32
Joined: Thu Nov 15, 2012 7:21 am
Has thanked: 7 times
Been thanked: 7 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Tom Stefanou »

Thank you for your reply but this is not the case...

if you see http://www.freebsd.org/doc/en/articles/ ... index.html

it mentions...

1.4.2 RS232-C Break Signal

RS232-C also specifies a signal called a Break, which is caused by sending continuous Spacing values (no Start or Stop bits). When there is no electricity present on the data circuit, the line is considered to be sending Break.

The Break signal must be of a duration longer than the time it takes to send a complete byte plus Start, Stop and Parity bits. Most UARTs can distinguish between a Framing Error and a Break, but if the UART cannot do this, the Framing Error detection can be used to identify Breaks.

In the days of teleprinters, when numerous printers around the country were wired in series (such as news services), any unit could cause a Break by temporarily opening the entire circuit so that no current flowed. This was used to allow a location with urgent news to interrupt some other location that was currently sending information.

In modern systems there are two types of Break signals. If the Break is longer than 1.6 seconds, it is considered a "Modem Break", and some modems can be programmed to terminate the conversation and go on-hook or enter the modems' command mode when the modem detects this signal. If the Break is smaller than 1.6 seconds, it signifies a Data Break and it is up to the remote computer to respond to this signal. Sometimes this form of Break is used as an Attention or Interrupt signal and sometimes is accepted as a substitute for the ASCII CONTROL-C character.

Marks and Spaces are also equivalent to “Holes” and “No Holes” in paper tape systems.

Note: Breaks cannot be generated from paper tape or from any other byte value, since bytes are always sent with Start and Stop bit. The UART is usually capable of generating the continuous Spacing signal in response to a special command from the host processor.
so this is what i am after...

Tom Stefanou
Posts: 32
Joined: Thu Nov 15, 2012 7:21 am
Has thanked: 7 times
Been thanked: 7 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Tom Stefanou »

I have tried with the code attached but the break signal is not detected...
Attachments
BreakTest.fcf
Trying to create break signal...
(16.68 KiB) Downloaded 277 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by LeighM »

It looks as though you need to determine what exactly the receiving equipment is expecting.

What Enamul quoted is correct in terms of what most equipment understands to be a break, that is the sending of a continuous spacing value exceeding the normal data plus syncing bits.

Your quote mentions two specific conditions, a break of >1.6 seconds and “no electricity present”.

If your equipment is expecting a break of a specific duration I would suggest that you disable the UART Transmitter (clear the TXEN bit) and then output a low to RC6 for the required period (>1.6s)

A “no electricity present” condition is going to be difficult to achieve depending upon your RS232 circuitry.

Tom Stefanou
Posts: 32
Joined: Thu Nov 15, 2012 7:21 am
Has thanked: 7 times
Been thanked: 7 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Tom Stefanou »

I contacted the author of PuTTY and he replied to me with this...
> Could you please explain to me what happens when someone sends the
> break key command (Alt+B) and is connected to a device through
> serial port?

It causes a pattern of voltages on the serial wire which is
different from any pattern used to send an ordinary character.

http://en.wikipedia.org/wiki/UART gives more detailed information. A
brief summary is:

- when the line is idle it remains at the high voltage representing
a 1 bit.

- to send an ordinary character, the line goes low (0) to indicate
that a character is about to start, then it sends eight (or
however many) bits of data, perhaps a parity bit, and then goes
back to the idle 1 state.

- So when the line initially goes low, the receiver can always
expect that it will go back to 1 within a certain length of time
if an ordinary character is being sent.

- A break signal means that the line goes low and stays that way
for longer than the expected duration of a character, so that the
receiver can't interpret it as any ordinary character.

Cheers,
Simon
So could you please guys send me a sample code for that?
I cannot underestand how to implement it.
Thank you all in advance.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Enamul »

A break signal means that the line goes low and stays that way
for longer than the expected duration of a character, so that the
receiver can't interpret it as any ordinary character.
That's seems not so difficult in Flowcode if you don't need that in between any character send. Simply you can control the TX bit and keep that low for your desired time duration..We can help you in coding if you mention the amount of time you need to keep the line low..
Please also tell us whether any easy way to test break signal so that we can test before posting.
Enamul
University of Nottingham
enamul4mm@gmail.com

Tom Stefanou
Posts: 32
Joined: Thu Nov 15, 2012 7:21 am
Has thanked: 7 times
Been thanked: 7 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Tom Stefanou »

Thank you for your reply.
I suppose any time should be ok.
I mean that if someone can send me the code i will adjust it to work from a time perspective.
This signal will go to a router.
I can test and le you guys know, i think it is easier.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by LeighM »

could you try something like the attached, sorry I have not had chance to test it
Attachments
SendBreak.fcm
(2.22 KiB) Downloaded 267 times

Tom Stefanou
Posts: 32
Joined: Thu Nov 15, 2012 7:21 am
Has thanked: 7 times
Been thanked: 7 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Tom Stefanou »

I tried and router does not detect it...

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Benj »

Hello,

One option may be to connect a free output pin to the RS232 side of the RS232 transceiver chip using a NPN transistor. When you want the break to happen you output a 1 to the pin controlling the transistor base and this will have the effect of pulling the transmit line to ground.

Here is a quick circuit drawing though I'm not 100% about the resistor values you will need. It may also be wise to pull the RS232 transmit signal to -12V rather then Ground but I think you need to do some experimentation.
Schematic.jpg
(91.86 KiB) Downloaded 1475 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by LeighM »

Can you test the signal on the RS232 transmit line?

It should normally be negative (-3v to -15v) and the SendBreak should cause it to go positive (+3 to +15V) for 2 seconds

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Benj »

Aha ok maybe a PNP type transistor to control the signal with a NPN transistor driving the PNP base to allow the microcontroller to switch the PNP on and off.

Tom Stefanou
Posts: 32
Joined: Thu Nov 15, 2012 7:21 am
Has thanked: 7 times
Been thanked: 7 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Tom Stefanou »

1) Ben thank you for the drawing but i cannot try tis since i am experimenting on an easypic5 dev board and i cannot connect anything there
besides the terminal software does not make any hardware modifications to the serial port, right?
2) I measure the voltage on the tx line and nothing changes
it is -7,46V when idle and the same when i send break signal.
i have increased time to 12sec to be able to see what happens with the voltages

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by LeighM »

you might need to disable the UART (as well as the TX pin), in the C code
rcsta.SPEN = 0;

Tom Stefanou
Posts: 32
Joined: Thu Nov 15, 2012 7:21 am
Has thanked: 7 times
Been thanked: 7 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Tom Stefanou »

I tried that and nothing changes...
btw, i noticed that when it transmits voltage increases by 0,23V only goes from -7,46 to -7,23
I added the disable uart code and nothing changes same voltages

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by LeighM »

With normal character transmission you would need an oscilloscope to see the transitions from mark to space, the pulses will be too quick for you to read on a Digital Voltmeter

Tom Stefanou
Posts: 32
Joined: Thu Nov 15, 2012 7:21 am
Has thanked: 7 times
Been thanked: 7 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Tom Stefanou »

Guys i want to thank you all for providing a solution to my question.
What you send me after adding the disable uart part was ok.
it was just that delay was too long
it needed 100mS to get the break signal.
Again thank you all!

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by LeighM »

Maybe you should next try a very simple flowchart that does not involve a UART, just toggle portc pin 6 say with 10 seconds on, 10 seconds off, to check we are on the correct pin

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by LeighM »

ah, OK, well done

Tom Stefanou
Posts: 32
Joined: Thu Nov 15, 2012 7:21 am
Has thanked: 7 times
Been thanked: 7 times
Contact:

Re: Sending a break signal using 16F877 usart

Post by Tom Stefanou »

Hello again guys....
I am not sure if i have to reply here or if i have to post a new topic so sorry about that.
I am reading from the serial port and display data to an lcd module.
What is the proper way of reading everything from the serial port buffer?
I have searched the forum and only thing i could find was a topic from flowcode 3 where BenJ had updated the ecxample of rs232 to use an interrrupt.
To be honest i could not find that implemented in flowcode 3 or 5 examples.
So i know i am missing a lot of characters compared to the ones i should receive.
How am i supposed to do the reading from the serial port?
Thank you for your time!

Post Reply