Interpreting serial via data analyser

WhiteSpace

Well-known member
I wonder if someone could give me a pointer please. As mentioned on another thread, I've been changing my IROUT/IRIN remote control vehicle project to SEROUT/SERIN via infrared. I first tried HSEROUT/HSERIN and have switched to "ordinary" serial for various reasons. Serial via IR is working very well, actually rather faster than IRIN. I would like to check the time between bytes and the duration of each set of commands, in order to improve the handling at the receiver end.

I have a 28x2 creating a 33 kHz carrier wave on one pin, combined through a transistor AND gate with the SEROUT from another pin set as:

Rich (BB code):
serout IRLED, N2400_16, (LeftSendByte);
and sending via IR LED to the receiver unit. My understanding from manual 2, p.218 is that "N" mode is inverted, idle low, pulse high, so I would expect the LED to be lit for 1 and dark for 0. It all seems to be working fine - the bytes are being received at the other end (the IR sensor is active low, so the SERIN mode is set to to T2400_16).

However, while measuring the duration of a bit (seems to be about 380 microseconds) and the length of a byte (about 3.7 ms), I noticed that the bits appear the opposite way round to how I would expect - so what I take to be 1s are low and 0s are high.

Here are a couple of examples. I've been using PCB scope, and in fact this exercise has been quite useful, because I have really learned how to use it. I've run a number of bytes, chosen for their distinctive patterns in binary.

So here is the byte 126.

Screenshot serial 126.png

Channel 1 is the signal at the base of the transistor handling the carrier wave. Channel 2 is the signal at base of the transistor handling the serial.

126 in binary is 01111110. I think what the scope is showing is a start byte immediately followed by the "0" LSB (producing the double-length high on the left), then the 6 "1" bits, then the "0" MSB. But that doesn't correspond to what I understand is being sent from the Picaxe - I ought to be seeing the inverse of this: a low bit, six high bits, a low and then a stop bit.

Similarly 130 looks like this:

Screenshot serial 130.png

130 is 10000010, so I would expect a high bit at each end, with lows in between. Instead there is a double length high, presumably start bit, LSB, then a low for bit 1, then 5 high bits (which checks with the period between the cursors, roughly 5 x 390 microseconds), then low MSB.

What blindingly obvious point am I missing here, please? Thanks very much.
 

AllyCat

Senior Member
Hi,

The "RS232" (serial) protocol is "confusing" because it sends LSbit first (i.e. the reverse sequence to the bits as they appear in a % format byte) and it idles at the Logical "1" level, so the Start bit is actually a "0" (and the Stop bit a "1"). Therefore you can't actually see a complete single Byte (because the Stop bit merges with the Idle level).

Here's a SCREENSHOT that I created for post #1 of Another Thread which shows a "multiple exposure" of two "concatonated" ASCII characters (consecutive, touching at the vertical centre-line). Thus the first (Start) bit, the Eighth Data bit (values over 127) and final (Stop) bit show as fixed levels whilst the seven ASCII data bits ("printable" characters 32 - 127) take both values to show as "data eyes". It's the PICaxe Editor's Idle Low "N" format so "1" is Low and "0" is High. The blue line marks the start of an interrupt initiated by the first Start bit.

Cheers, Alan.
 
Last edited:

WhiteSpace

Well-known member
Thanks @AllyCat - how do you know everything about Picaxe, if it's not a rude question? I had worked out that the serial sends LS bit first, and I had also deduced the 0 start bit from the double-length high at the start of the 126 and 130 bytes described above, resulting from the combination of the 0 LSB and the 0 start bit. But I had understood from the manual that "N" meant idle and 0 low and 1 high (p218 explains: "A ‘N’ baud rate idles low, with data pulse going high" , which is the opposite of what the scope seems to be showing (and the opposite of your comment above that "It's the PICaxe Editor's Idle Low "N" format so "1" is Low and "0" is High"). What am I missing? Thanks
 

AllyCat

Senior Member
Hi,

I guess I know quite a lot about PICaxe because I've been a member of the forum for almost 10 years and both use and measure what the chips do. But also, I was an electronics "hobbyist" as a child and worked in the electronics industry for around 40 years, including a fair amount of time writing programs in Assembler for various microcontrollers. And some of that time was spent writing my own "In Circuit" Bootloaders and Embedded Debuggers, which are very much the way that PICaxe and other microcontroller-based systems are now developed. "RS232" was the "standard" interface, long before USB, I2C, Bluetooth, WiFi or even CAT5 Network cables.

"RS232" serial communications were developed well before PICaxe (or my education), at least by the middle of the last century, and the basic principles long before that. I don't know the exact history, but it dates back to when the primary way to communicate by Telegram or (later) with a computer was via a "Teleprinter" (a kind of electric typewriter) or a mechanical "Terminal", only later to be replaced by line printers and electronic (CRT) monitors, etc.. The specified signalling voltage levels were around plus and minus 15 volts, which were not large compared with the voltages used by motors or (magnetic) solenoids, etc.. Again, I don't know why it was chosen to be "Idle Low" (but to call it a logic "1") or why the LS bit is sent first, but sometimes it's better to have an agreed "standard" than to look for the "best" technical or logical solution. Similarly, data (bit) rates probably started at 50 and 75 baud (perhaps doubling was "too difficult" with mechanical components) and then just got repeatedly "doubled up" through 2400 to 76.8k, or sometimes 14.4 to 115.2k, etc..

The "N" usually represents "Negative" or "Not" (although for RS232/PICaxe it could be "Normal"), which I think was used before the "T" (for "True" or "TTL"), but I've always preferred the "Idle Low/High" descriptions (because N is the Negative of what?). However, the +/-15 volts is "too high" for most electronics now (perhaps it was even when RS232 was defined) so it is assumed to use an "Amplifier" and the simplest amplifiers generally invert the signal (e.g. a single transistor or valve/tube), thus the signal driving that amplifier is "T" (True/TTL) polarity. Eventually, a negative supply rail became "inconvenient", so RS232 Receivers were designed to accept zero volts (i.e. less than 1 or 2 volts) as the "Low" level (even though it actually represents a logical "1").

Therefore, the "correct" RS232 interface used an inverting amplifier at the "Transmit" end and a compensating inverter at the "Receiver", later using one of the ubiquitous MAX232 chips to invert the signals and generate "boost" voltages. But PICaxe chose to just attenuate the input signal (with a resistor); a lower-cost solution and not unreasonable because it became a simple "Idle Earth" interface. However, nowadays, the majority of "RS232" serial interfaces have abandoned the amplifier/inverter stages and we often have the typical "TTL" Idle-High level, called logical "1" (similar to the I2C bus, but that does use MS bit first).

Cheers, Alan.
 

papaof2

Senior Member
We had problems with RS232 communications in a multi-story building and engineers were brought in to determine why the shells (ground) of some shielded RS232 cables were drawing sparks when connected to a CRT terminal or printer some floors away.
Turned out to be a major problem with the AC power neutral/earth bonding/grounding and they spent $$$$$$ fixing the problem. The fact that there was an electronic long distance telephone switching machine in that building which was affected by those stray currents had a lot to do with that expenditure ;-) Even with some appreciable AC current on the shield of the cable, the RS232 signal still got through.

The original +/- 15 volts of RS232 was probably to have a signal which was minimally affected by the surrounding electrical activity - such as the brushed motors in teleprinters, etc.

In the very early days of "work from home", I had a Tektronix 40XX terminal and an 80 character line printer (100+ pound boat anchor) so I could dial in and check our 24/7/365 operation. 2400 baud modem with a statistical multiplexer at each end so the one line could support a terminal and a printer. Three lines of text to the terminal, then one line to the printer. Slow? Yes. Huge by current standards? Yes. But the important factor was that it worked and I had access to the various control and monitoring systems at 3AM without driving 20 miles.
 
Top