Wednesday 14 January 2015

Fake MAX3232 RS232 line drivers ?

This is my second post about the plague of knock-off ICs.

The job was simple: I needed an RS232 interface on a Raspberry Pi so that I could use it to log console output from a misbehaving router (don't ask).  I could have picked up one of the millions of USB-to-RS232 converters on eBay (and run the gauntlet of FTDI's clone-bricking updates). However, I have read mixed reports of the stability of the drivers for these adapters in the Raspberry Pi kernel. Besides, there actually is a UART baked into the Pi SoC. The problem is that it only works at 3.3V logic levels so it can't be connected directly to a device that uses RS232 voltages. That's OK...I just picked up one of these and wired it to the appropriate GPIO pins on the Raspberry Pi's I/O connector



Its a simple device.  It converts between logic-levels (this version does either 5V or 3.3V)  on the pin-header and and RS232 voltage levels on the DB9 connector.  All that's on it is a MAX3232 line-driver and four ceramic capacitors (used by a charge-pump in the IC to generate RS232 voltages). It looks like the circuit (such as it is) is lifted directly from the IC's datasheet.

Simple, eh? No.  It worked just fine talking to a PC, but when I connected it to a Cisco 1841 router, very strange things happened.

When I sent a character from the Raspberry Pi to the router (I think I might have just hit carriage-return), this absolute explosion of characters was the result


Wow...what's going on here !  Out with the oscilloscope.  Here is an 'A' being sent from the Pi to the router:-


The blue trace is the Pi's TX line and the yellow trace is the Pi's RX line.  So far so good.  However, a few moments (about 68ms, to be exact) later, this happens:-


As far as I can see, what is happening is that when the Cisco echos back the character it received (yellow trace), there is crosstalk onto its RX (blue), so the router is seeing an "echo" of its own character (but corrupted).  The router echos that character back also, sees another "phantom" character on its RX etc etc.

As I mentioned, Raspberry Pi talking to a PC works just fine.  Sure enough, looking at that on the oscilloscope...


...there are little "spikes" evident on the Raspberry Pi TX line, but nothing like as bad and apparently not enough to cause a problem.

So the question was, where (and how) was the crosstalk happening ?  A few possibilities:-

  • Within the router itself (highly unlikely, or the router wouldn't work with a PC either and would be basically useless)
  • Within the console cable (that was my first theory when  was using a patch-cable, but I replaced that with a flat-8 cable which keeps the RX and TX lines separated by a few mm and that made no difference)
  • On the adapter board somewhere (most likely, but why, then, did I see hardly any crosstalk at all with the RPi talking to a PC or to a switch ?)

To test the theory that the crosstalk was happening on the adapter board, I disconnected the RX from the router from the TX line on the adapter board and used to oscilloscope to watch (a) the (now-disconnected) RX line from the router and (b) the TX line on adapter board separately.


Bingo !!  The line from the router was clean as a whistle (thus exonerating both the router and the console cable) but the TX line from the adapter (which shouldn't be generating any signal at all) was worse than ever:-


Yellow is the signal coming up from the router (console messages during the router boot sequence); blue is the output from the line-driver module (which should be completely flat).

I think it is a question of voltage.  The router uses a relatively high voltage on its TX line...around +/-10V.  Still perfectly within the RS232 specifications (which allows for  +/-12V) but higher than either a Cisco switch I tested or the PC use (both about +/-6V).  It looks like the higher voltage breaks down the line-driver.  Sure enough, conducting the same experiment with a switch instead of a router...


So it looks like the MAX3232 line-driver doesn't like +/- 10V on the RS232 side.  It should - according to the data-sheet it should be good for +/- 25V:-


I did one more test to confirm the theory: I put a couple of back-to-back 3.3V zener diodes in between the router TX and the adapter RX.  This has the effect of dropping the voltage that the adapter sees by about 4V.


Sure enough, the problem goes away (I didn't bother saving an oscilloscope trace but - trust me - it was perfect: no signal at all leaking onto the adapter TX). Its really looking like its the voltage that is causing the problem.

So at what voltage does the problem kick in? If I feed a square wave to the RX pin on RS232 side while watching what appears on the TX pin (nothing should) and gradually crank up the voltage, we should be able to find out.  In each of the screen-captures below, the yellow traces is the signal being fed to the RX pin and the blue trace is what is coming out of the TX pin.

Starting with 19.2V peak-to-peak...


No problem so far.  Increasing to 19.4V peak-to-peak...


...and 19.6V peak-to-peak...


...by now we would probably be seeing problems.  Increasing the voltage to 20.6V peak-to-peak...


...and we would definitely be seeing problems.

If a real MAX3232 IC (mis)behaves like this, I'll eat my hat.  I have looked closely at the IC on the adapter and - to my untrained eye - it looks fine (decent enough quality moulding, quality of laser etching looks OK) but I'm willing to bet that these are fakes.

I would really love to get a known-genuine MAX3232 IC from a reputable supplier and use it to replace the suspect one on the adapter, but they only seem to be available in quantities of 2500 (at about €1 each).  Sorry, but I'm just not that interested.  However, if someone wants to send me a few genuine MAX3232s (you will need to pinkie-swear that they are definitely the real thing) I'll be happy to do the test and report the results here.



PS: An interesting thing I learnt in the course of doing this project is that the Raspberry Pi (the Raspbian image, anyway) runs a serial console on its built-in UART. A serial terminal emulator connected at 115,200 baud will receive a login prompt through which you can log in to the Raspberry Pi.  You never know when that will come in handy.


Tuesday 13 January 2015

Spot the Chinese knock-off.



The IC on the top is the genuine article (its an LED driver). It costs about €10 (+VAT) from a reputable supplier in small quantities (down from nearly €20 a couple of years ago). The IC on the bottom came from eBay. I got ten of them for €3.09. Not €3.09 each...€3.09 for all ten.

Although you can't see it (because the quality of the laser etching is terrible and I couldn't get it to photograph), it has the Maxim logo (rough around the edges if you look closely), the same part number and at a glance looks like the real deal. Its only when you compare them side-by-side that you notice that the knock-off is physically smaller (that's not an optical illusion...it actually is smaller), has poorer quality legs, poorer plastic encasing and the laser etching is nothing like as good. More pertinently, at first it didn't work in the circuit I put it into where the real one did (although, to be fair, I was playing a tiny bit fast-and-loose with the power-supply decoupling: once I fixed that, the knock-off worked just fine).

If you can't trust randomly-selected eBay sellers in the Orient who can you trust? It makes me wonder if that €30 Rolex I got is real.

Monday 12 January 2015

Where does Blogger store pictures?

They say that a picture tells a thousand words.  Imagine my dismay, then, when I noticed that all of the pictures from my recent blog posts (all the ones I had created since switching to Blogger, actually) had vanished.  Thousands and thousands of my bons mots lost to the Internet.  Not since the burning of the library in Alexandria has such a misfortune been visited upon the store of human knowledge.

Thankfully, I had copies of most of the missing pictures and they have been restored to their rightful place, but I'm still not completely sure what happened. It turns out that photos you upload directly to Blogspot are actually stored in Google Plus (used to be on Picasa).  It is possible that I did a bit of a clear-out of my Google Plus photos at some point and accidentally deleted them.  I don't remember doing it, but its the kind of thing I would do.

Anyway, this blog post is part warning, part experiment.  Here is a pretty picture:-


It is one of the first pictures I took with my Nikon D50 when I got it almost 10 years ago. Its a fantastic camera and is still my weapon of choice when I need the best possible image quality. It still beats the socks off any other camera I have for image quality and speed (but not portability!).

However, none of that is of any interest to you, the reader.  What is interesting is that I am going to go looking to see where in Google's universe it winds up.  I am also shortly going to delete the picture in Google+ to see what happens.  I'll update this post with my findings.

UPDATE 13/Jan/2015: OK...I have just deleted the picture using the "Photos" app on my Android phone.  So far, no ill-effects on this blog entry, but lets see what happens

UPDATE #2: It didn't happen straight away, but a little while (perhaps an hour) after I deleted the photo from my phone, it also disappeared from the blog. Im rather proud of the photo, so here's another copy of it.