Page 1 of 1
Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 7:45 am
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.
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 8:50 am
by medelec35
Hi Tom,
When I want a line break I send:
Followed by char 10
Char 13 = Carriage return
Char 10 = Line Feed
Not 100% sure if that's what your after or not?
Martin
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 9:11 am
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
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 9:13 am
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...
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 9:22 am
by Tom Stefanou
I have tried with the code attached but the break signal is not detected...
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 10:12 am
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.
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 12:43 pm
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.
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 1:54 pm
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.
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 2:56 pm
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.
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:02 pm
by LeighM
could you try something like the attached, sorry I have not had chance to test it
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:08 pm
by Tom Stefanou
I tried and router does not detect it...
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:12 pm
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.
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:17 pm
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
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:20 pm
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.
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:24 pm
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
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:32 pm
by LeighM
you might need to disable the UART (as well as the TX pin), in the C code
rcsta.SPEN = 0;
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:37 pm
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
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:43 pm
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
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:45 pm
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!
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:46 pm
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
Re: Sending a break signal using 16F877 usart
Posted: Thu Nov 15, 2012 3:47 pm
by LeighM
ah, OK, well done
Re: Sending a break signal using 16F877 usart
Posted: Fri Nov 16, 2012 10:35 am
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!