Pages: [1]   Go Down
Author Topic: Inerfacing with smart card  (Read 3594 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
I want to read the data of a smart card with arduino but it isn't as simple as i thought.
I have a smart card that I don't know of which type it is, so I discover that by sending a "answer to reset" command to the card I should get a 4 byte string that identify the card type. My problem now is how to get this code.

I've  plugged the card to arduino by following this image:

1. VCC (alimentation)
2. RST (remise à zéro)
3. CLK (horloge)
4. D+ (USB Inter-chip)
5. GND (masse)
6. SWP
7. I/O (entrée/sortie)
8. D- (USB Inter-chip)

I've plugged 1 with the 5v pin
2 with the 3 analog pin
3 with the 5 analog pin
5 with the GND pin
7 with the 4 analog pin

To send an ATR command you have to held the reset pin high, send one clock, relase the reset pin and then you can read the 4 byte data.
Here is shown well:

I've wrote this code:
Code:
#include <Wire.h>

int resetPin=3;
int clockPin=4;
int dataPint=5;

void clock(){
  analogWrite(clockPin, 1023);
  delay(70);
  analogWrite(clockPin, 0);
}

void setup(){
 
  Wire.begin();
  Serial.begin(9600);
  Wire.beginTransmission(0x00);

  analogWrite(resetPin, 1023);
  clock();
  analogWrite(resetPin,0);
  Serial.println(Wire.receive());
 
  Wire.endTransmission();
}

void loop(){}

Obviously it doesn't work... Any idea about how to do this operation? I can't find any reference on the internet...

Thanks
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so I discover that by sending a "answer to reset" command to the card I should get a 4 byte string that identify the card type.
Quote
To send an ATR command you have to held the reset pin high, send one clock, relase the reset pin and then you can read the 4 byte data.
Quote
1. VCC (alimentation)
2. RST (remise à zéro)
3. CLK (horloge)
Quote
I've plugged 1 with the 5v pin
2 with the 3 analog pin
3 with the 5 analog pin
To send the ATR command, you set the reset pin (#2 on the card) HIGH. Since you have connected the reset pin on the card to an analog pin, which is, by definition, input only, how did you "held the reset pin HIGH"?

Since you have connected the clock pin (#3 on the card), to an analog pin, which is, by definition, input only, how did you "send one clock"?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi There,
There  are a few things you need to be aware of with smart cards:
1) Know if the card is just a memory chip or a proper microprocessor card.
2)Smartcards (SC's) have two protocols T0 and T1. The comms from the chip is different for both.
3)Checkout http://www.cardwerk.com/smartcards
4) the bottom two contacts (4 and smiley-cool are not used = RFU
5) Some SC's work on lower voltages than 5v, so just be carefull not to pop the device.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry forgot also:
6) All SC's initial baud rate is 9600, then you can get the max baud rate available from the ATR.
7) Atr's are much longer than 4 bytes most of the time. like :
   00 31 C0 71 D6 65 13 0D 01 81 01 83 
 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the answers.

@PaulS
Quote
Since you have connected the clock pin (#3 on the card), to an analog pin, which is, by definition, input only, how did you "send one clock"?
That's my problem. Since I want to use the Wire lib to read the data (it makes things a lot easier), i had to plug the CLK line and the data line to analog pin #5 and #4. So I have no idea how to send one clock, i tried to do it in my code (see clock() function) but it doesn't work.
The problem with the Wire library is that it doesn't provide any support for a third line (the reset one trough which i need to send the ATR command) so i need to manually do the clock-thing...

@philicoe
Thanks for the infos!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So I have no idea how to send one clock, i tried to do it in my code (see clock() function) but it doesn't work.
Despite it's misleading name, the analogWrite() function affects digital pins only. It is doing nothing to the analog pin that the clock line is connected to.

You are going to need to connect the reset line to a digital pin, and set that pin's mode to OUTPUT, and use digitalWrite() to set that pin HIGH or LOW.

You'll need to look at how the wire library modifies the clock pin setting. Analog pins 4 and 5 are special in that they are the I2C pins, so, under the right circumstances, they can output data.

Finally, just a note, the maximum value for analogWrite is 255, not 1023.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Depending on what kind of smart card your trying to read it can actually be quite complex, the hardware is the easy part but if you want to actually see whats on the chip its quite and intense programming procedure. I've researched it a bit and I might possibly play with it for my next project.

Anyways keep us updated smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have made no progress...
Since you have called Wire.begin() you can't modify analog pin #4 and #5 unless with Wire lib functions...
Doing something like "digitalWrite(A5, HIGH); ... ; digitalWrite(A5, LOW)" doesn't work...
I can't understand how the Wire lib (or in general how the I2C protocol) threat the clock process: there is an explicited called clock() function or internally there is something like an oscillator that works continuously?
Any help?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Since you have called Wire.begin() you can't modify analog pin #4 and #5 unless with Wire lib functions...
Analog pins are input only. You can't modify them even if you haven't called Wire.begin().

Quote
Doing something like "digitalWrite(A5, HIGH); ... ; digitalWrite(A5, LOW)" doesn't work...
Sure it does. But, if you are trying to observe the effect on the analog pins, you are looking on the wrong side of the board. Despite the names, these functions affect the digital pins. Since the analog pins are input only, there are no functions to write to them.
Logged

United States (Texas)
Offline Offline
God Member
*****
Karma: 3
Posts: 525
Arduino socks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

from the playground


Quote
The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH:

pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);

care to clarify?

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

when I try this circuit, It doesn't worked.
I got output, when I used the product of microsd shield with FAT16 library.
http://www.tenettech.com/product.php?id_product=104
Regards,
Bala
Tenet Technetronics
Logged

Pages: [1]   Go Up
Jump to: