Ultra simple ISO-7816 Interface

While laying out a PCB for my SWP reader project I realized that I haven’t ever tested the ISO-7816 (aka contact) interface yet. I probably forgot that because it’s not all that difficult and not that interesting, but I’d rather see it working before I order PCBs.

So I spend an hour or two in the internet looking for inspiration how other people did it. There are lots of specialized chips for this purpose out there, but sourcing is always a problem and since it’s “just” a simple serial interface I was more interested in a simple hack that will work.

Turns out there are a lot of simple SIM/Smart-card readers out there that just do this, and they pretty much all look like this:

iso1

Here Q1 is running as a open collector driver with R1 as a pull-up resistor. This transistor will invert the signal, that’s why there is an additional inverter A1 in front of the base. R2 and C1 are the usual base-resistor and speed-up capacitor.

You’ll find variations of this basic circuit all over the net. Sometimes they omit the speed-up capacitor, sometimes you find buffers in the RX-UART path, but that’s it basically.

I heated up my soldering iron and gave this circuit a test drive, and lo and behold: It works as expected (aka good enough in practice).
So problem solved, move on.

Not so. In the middle of the night it came to me, that almost the entire circuit is unnecessary. What does it really do? On the Q1 collector we see a replica of the TX-UART signal. The SIM card IO pin (which is just an open collector IO-pin) is able to pull the signal down at will without causing a short to TX-UART.

RX-UART picks up this signal and echoes back either what comes from TX-UART or from IO. Neither pin is pulling up the signal, that’s what R1 is doing.

So how about this:

iso2

It’s working just the same, just faster and with less parts.

In case that TX-UART is transmitting, and IO is listening the singal will just pass R1. If TX-UART stops transmitting the UART will go into idle-state (logic high). This effectively ties R1 to VCC and we have exactly the same behaviour as with the more “complex” circuit.

If the SIM transmit something SIM-IO just pulls the line down to ground. A bit of current will flow out of TX-UART, but that’s fine. Compared to drive a LED from a GPIO pin that’s nothing.

If you feel inspired to try this out, here is a short how-to:

  • Configure the UART on the micro-controller side for 9600 baud, 8 data bits, two stop-bits and even parity.
  • Power the SIM VCC pin, have reset low.
  • Apply a clock signal 372 times the UART baud-rate: 3.57 Mhz.
  • Wait a little for the SIM/SmartCard to stabilize.
  • Raise the reset line to taking the SIM-card out of reset.

And then watch the Answer to Rest (ATR) signature arriving at your micro-controller UART-RX pin. You’re now ready to implement the ISO7816-3 T=0 or T=1 protocol and do some real data-exchange. With practically any micro-controller and just a simple resistor.

Oh, by the way. You’re allowed to let the IO pin of the SIM to pull down up to 500µA, so if you get problems with stray capacitance just lower R1. Minimum values are:

  • 3.6k for 1.8V supply
  • 6.6k for 3.3V supply
  • 10k for 5V supply.
This entry was posted in Uncategorized. Bookmark the permalink.

4 Responses to Ultra simple ISO-7816 Interface

  1. EB says:

    Can you please gave an example of the response of the UART? I am trying to use hyperterminal and TTL-232R-3V3 cable instead of a Microcontroller.

  2. Niclas says:

    Hi,

    I tested your easy solution and it didin’t work. I added a diode to get it working. Maybe you can explain why it wasn’t working in my setup.

    My improved circuit:
    http://imgur.com/a/hxgSJ

    Thanks for this nice post!

  3. Vishal Vaidhyanathan says:

    I’m able reset the SIM and get the ATR from it which I can observe on the oscilloscope. But when I try to decode the ATR using a TTL cable in my PC at 9600 baud rate, 8 data bits, even parity and 2 stop bits, I get garbage. Do you know why or can you share your thoughts on this?

  4. Nils says:

    Hi Vishal,

    If you can see the ATR binary data you’re almost there. If you receive garbage it sounds like a baud-rate problem. Make sure that the clock-signal that you provide is exactly 372 times faster than 9600 baud or 3571200 Hz.

Leave a Reply

Your email address will not be published. Required fields are marked *