APPLICATION NOTE. AVR1623: XMEGA Smart Card Reader. ATxmega128A1. Introduction. Features

Similar documents
AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

USER GUIDE EDBG. Description

AT88CK490 Evaluation Kit

APPLICATION NOTE. AT07175: SAM-BA Bootloader for SAM D21. Atmel SAM D21. Introduction. Features

CryptoAuth Xplained Pro

AT15007: Differences between ATmega328/P and ATmega328PB. Introduction. Features. Atmel AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. Secure Personalization with Transport Key Authentication. ATSHA204A, ATECC108A, and ATECC508A. Introduction.

AVR315: Using the TWI Module as I2C Master. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

APPLICATION NOTE. AT16268: JD Smart Cloud Based Smart Plug Getting. Started Guide ATSAMW25. Introduction. Features

AVR1510: Xplain training - XMEGA USART. 8-bit Microcontrollers. Application Note. Prerequisites. 1 Introduction

APPLICATION NOTE Atmel AT02509: In House Unit with Bluetooth Low Energy Module Hardware User Guide 8-bit Atmel Microcontroller Features Description

APPLICATION NOTE. Authentication Counting. Atmel CryptoAuthentication. Features. Introduction

APPLICATION NOTE. AT12405: Low Power Sensor Design with PTC. Atmel MCU Integrated Touch. Introduction

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AVR311: Using the TWI Module as I2C Slave. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

AVR1922: Xplain Board Controller Firmware. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

QT1 Xplained Pro. Preface. Atmel QTouch USER GUIDE

USER GUIDE. ZigBit USB Stick User Guide. Introduction

AVR127: Understanding ADC Parameters. Introduction. Features. Atmel 8-bit and 32-bit Microcontrollers APPLICATION NOTE

AVR106: C Functions for Reading and Writing to Flash Memory. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

AVR1900: Getting started with ATxmega128A1 on STK bit Microcontrollers. Application Note. 1 Introduction

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

APPLICATION NOTE. AT05558: Wireless Manufacturing Test Kit. Atmel ATmega256RFR2. Description. Features

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

AVR1321: Using the Atmel AVR XMEGA 32-bit Real Time Counter and Battery Backup System. 8-bit Microcontrollers. Application Note.

Using CryptoMemory in Full I 2 C Compliant Mode. Using CryptoMemory in Full I 2 C Compliant Mode AT88SC0104CA AT88SC0204CA AT88SC0404CA AT88SC0808CA

AVR126: ADC of megaavr in Single Ended Mode. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

udrive-usd-g1 Embedded DOS micro-drive Module Data Sheet

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR125: ADC of tinyavr in Single Ended Mode. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR115: Data Logging with Atmel File System on ATmega32U4. Microcontrollers. Application Note. 1 Introduction. Atmel

AT11805: Capacitive Touch Long Slider Design with PTC. Introduction. Features. Touch Solutions APPLICATION NOTE

AVR32788: AVR 32 How to use the SSC in I2S mode. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Atmel AVR1017: XMEGA - USB Hardware Design Recommendations. 8-bit Atmel Microcontrollers. Application Note. Features.

USER GUIDE. ATWINC1500B Hardware Design Guidelines - IEEE b/g/n IoT Module. Atmel SmartConnect. Introduction

How To Use An Atmel Atmel Avr32848 Demo For Android (32Bit) With A Microcontroller (32B) And An Android Accessory (32D) On A Microcontroller (32Gb) On An Android Phone Or

8-bit. Application Note. Microcontrollers. AVR282: USB Firmware Upgrade for AT90USB

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

TCP/IP MODULE CA-ETHR-A INSTALLATION MANUAL

APPLICATION NOTE. Atmel AT02985: User s Guide for USB-CAN Demo on SAM4E-EK. Atmel AVR 32-bit Microcontroller. Features. Description.

AN TDA8026ET - 5 slots smart card interface. Document information

APPLICATION NOTE. Atmel AT04389: Connecting SAMD20E to the AT86RF233 Transceiver. Atmel SAMD20. Description. Features

Application Note. Atmel ATSHA204 Authentication Modes. Prerequisites. Overview. Introduction

AN3332 Application note

Using the RS232 serial evaluation boards on a USB port

8051 Flash Microcontroller. Application Note. A Digital Thermometer Using the Atmel AT89LP2052 Microcontroller

General Porting Considerations. Memory EEPROM XRAM

AVR1318: Using the XMEGA built-in AES accelerator. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AT09333: USB Host Interface (UHI) for Communication Class Device (CDC) Introduction. Atmel Microcontrollers APPLICATION NOTE

AVR32138: How to optimize the ADC usage on AT32UC3A0/1, AT32UC3A3 and AT32UC3B0/1 series. 32-bit Microcontrollers. Application Note.

APPLICATION NOTE. Atmel AT01095: Joystick Game Controller Reference Design. 8-/16-bit Atmel Microcontrollers. Features.

AVR287: USB Host HID and Mass Storage Demonstration. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1600: Using the XMEGA Quadrature Decoder. 8-bit Microcontrollers. Application Note. Features. 1 Introduction. Sensors

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

AN2680 Application note

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

Application Note. C51 Bootloaders. C51 General Information about Bootloader and In System Programming. Overview. Abreviations

8-bit RISC Microcontroller. Application Note. AVR910: In-System Programming

SAMA5D2. Scope. Reference Documents. Atmel SMART ARM-based MPU ERRATA

AT12181: ATWINC1500 Wi-Fi Network Controller - AP Provision Mode. Introduction. Features. Atmel SmartConnect APPLICATION NOTE

Atmel SMART ARM Core-based Embedded Microprocessors

MODFLEX MINI GATEWAY ETHERNET USER S GUIDE

APPLICATION NOTE. RF System Architecture Considerations ATAN0014. Description

AT91SAM ARM-based Flash MCU. Application Note

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

Using Altera MAX Series as Microcontroller I/O Expanders

MFRD52x. Mifare Contactless Smart Card Reader Reference Design. Document information

Application Note. Atmel CryptoAuthentication Product Uses. Atmel ATSHA204. Abstract. Overview

M95 Dual SIM Application Notes

AN2824 Application note

SN 132 SNAPstick QUICK START GUIDE

AN3155 Application note

Atmel AVR ATxmega384C3 microcontroller OLED display with pixels resolution Analog sensors. Ambient light sensor Temperature sensor

Application Note. 8-bit Microcontrollers. AVR272: USB CDC Demonstration UART to USB Bridge

Two mechanical buttons Two user LEDs Four expansion headers. Board controller with USB interface. One power LED and one status LED

AND8336. Design Examples of On Board Dual Supply Voltage Logic Translators. Prepared by: Jim Lepkowski ON Semiconductor.

The I2C Bus. NXP Semiconductors: UM10204 I2C-bus specification and user manual HAW - Arduino 1

8-bit Microcontroller. Application Note. AVR415: RC5 IR Remote Control Transmitter. Features. Introduction. Figure 1.

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

Measurement and Analysis Introduction of ISO7816 (Smart Card)

AN3265 Application note

AVR134: Real Time Clock (RTC) using the Asynchronous Timer. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR245: Code Lock with 4x4 Keypad and I2C LCD. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. Atmel LF-RFID Kits Overview. Atmel LF-RFID Kit. LF-RFID Kit Introduction

DATASHEET. ADAM Arduino Display Adaptor Module. Arduino Compatible Shield P/N: 4Display-Shield-FT843 For the 4D Systems 4DLCD-FT843 Display

Figure 1. 8-Bit USB Debug Adapter

GPS/GLONASS SiRFstarV Evaluation Kit EVA5100-A

AN3998 Application note

Transcription:

APPLICATION NOTE AVR1623: XMEGA Smart Card Reader ATxmega128A1 Introduction This application note describes how to use an Atmel AVR XMEGA device to connect to a smart card. The supplied code can easily be ported to support any Atmel device (ATmega, tinyavr, XMEGA, UC3, SAM) containing a timer capable of outputting a high frequency clock signal at an I/O pin, an U(S)ART, and optionally a TWI/I 2 C module. Features ISO7816 comparable smart card reader Optional standalone smart card reader functionality TWI/I 2 C control interface Hardware suggestions for both class C and class B smart cards (1.8V and 3.0V) Out of the box support for externally clocked asynchronous smart cards Note: Some of the UC3 and SAM devices also offer a hardware solution for an ISO7816 interface, which does not rely on any external components for achieving half duplex serial communication.

1 Smart Card Physical Interface The smart card interface consists of up to eight connections, as seen in Figure 1-1. An example of a pinout is listed in Table 1-1. Figure 1-1. Smart Card Example Table 1-1. Pinout Example Pin number Pin name Description 1 VCC Driving voltage (1.8 5.0V) 2 RST Reset pin (can be active low or high) 3 CLK Clock signal (1-5MHz) 4 AUX Not used for this application 5 AUX Not used for this application 6 GND Common ground 7 VPP Programming voltage (not used) 8 I/O Half duplex serial communication pin For this application only the five connections named VCC, GND, RST, CLK, and I/O will be used. A detailed description of the different signals is given in the following sections. 1.1 VCC Supply Voltage The smart card standard is divided between three different classes, separated by their supply voltage requirements: class A: 5.0V, class B 3.0V, and class C 1.8V. This application note will describe a single supply class B interface and a dual class B + class C interface. Support for the different classes can be obtained with minor changes to the circuitry and code. 1.2 CLK Clock Signal Some smart cards comes with internal clock, but many rely on the reader to provide a clock signal. According to the ISO7816-3 standard this clock has to be between 1 to 5MHz. This application note will utilize a timer to generate this signal. 1.3 RST Reset Signal The smart card is reset and forced into a known state by activating the reset signal. The smart card standard does not dictate if this should be an active high or active low signal; a careful procedure should therefore be followed when resetting a smart card. This procedure is described in Section 3.2. 2

1.4 I/O Half Duplex Serial Communication Pin This pin is used for serial communication and can be read by simply connecting it to the RX pin of one of the XMEGA s USARTs. To allow two-way communications, this signal should be connected to the USART RX pin trough 1kΩ of series resistance and directly to the USART TX pin, as illustrated in Figure 1-2. 1.5 VPP Programming Voltage Pin This pin is used for programming the smart card and will not be used in this application. 1.6 AUX Auxiliary Application Dependent Pins These pins can be used for application specific purposes like USB or similar. These pins will not be used in this application note. 1.7 GND Ground Common ground connection; this pin should be connected to the digital ground used for the XMEGA device. 1.8 Resulting Connections Figure 1-2. Resulting Connections The five connections between the smart card and the XMEGA are illustrated in Figure 1-2. The smart card I/O pin is connected to the XMEGA RX pin trough a 1kΩ series resistor and directly to the TX pin, as described in Section 1.4. The figure also illustrates the communication interface used between the smart card reader and an application MCU. 3

2 Power Considerations As mentioned earlier, smart cards run on one of three possible supply voltages, depending on their class. For this example the smart card VCC pin will be connected directly to an XMEGA GPIO pin. The ISO7816 standard specifies that smart cards can draw up to as much as 100mA. This exceeds the limit for how much current can be sourced by an XMEGA GPIO pin, but for demonstration purposes in this application the smart card is powered directly from the GPIO pin on the XMEGA device. For an end application it is therefore recommended using an external power supply to power the smart card. Applying power to a smart card before it is properly seated in its socket could result in voltage being applied to pins other than the smart card VCC pin, thereby damaging the smart card. A controlled power supply should therefore be used to ensure power is only supplied to the smart card when it is properly inserted into the socket. 3 Interfacing a Smart Card For this application note the smart card I/O pin and RST pin will be used to communicate with the smart card. The I/O pin is a bidirectional interface, and is driven from both the smart card itself and the XMEGA. The reset pin (RST) is controlled solely by the XMEGA and is used to ensure the smart card is in a known state before communication is initiated. 3.1 Powering and Activating a Smart Card Both active low and active high reset configurations are used for different smart cards. Because of this, special care needs to be taken when powering a smart card. The ISO7816 standard dictates how this should be done. The procedure should be as follows: 1. RST is pulled low. 2. The smart card is powered. 3. The interfacing device gets ready for incoming data. 4. A stable clock signal is provided to the smart card CLK pin. 5. Continue with the reset procedure, see Section 3.2. 3.2 Resetting the Smart Card When resetting a smart card, the card should answer with an Answer-to-Reset (ATR) (see Section 3.3 for more information about ATR). A smart card is reset as follows: 1. Pull the RST line low. 2. If no ATR arrives within the next 40 000 cycles, it is assumed the smart card has an active high reset, and the RST signal should be pulled high. 3. If an ATR still does not arrive within the preceding 40 000 cycles, it is assumed there is an issue with the interface, and the reader, i.e. the XMEGA device, should deactivate the connection to the smart card and the connections should be investigated. 4

3.3 Answer to Reset (ATR) An ATR consists of a number of bytes describing the connected smart card. The exact content is specific to different smart cards, and depends on their applications. For details on this, refer to your specific smart card data sheet. 3.4 Character Frame A smart card character frame is defined very similar to a standard U(S)ART frame. The frame consist of one start bit, then eight data bits b1-b8 (one byte), an even parity bit and two guard bits, as illustrated in Figure 3-1. Figure 3-1. The Smart Card Character Frame The transmitting device (either the smart card or the reader) should leave the I/O line floating during the guard interval. If the receiver detects parity errors, it should pull the I/O line low to notify the transmitter to retransmit the data byte. If a transmission problem is signaled, the sender should re-transmit the character a number of times, before transmission is considered impossible, and communication is aborted. For the solution presented in this application note, the number of attempts that should be made is user configurable, with an upper limit of seven. A smart card can transmit data either asynchronously or synchronously. This application note will only cover asynchronous transfer, as separate peripherals are used for clock generation and I/O line read/write operations, clocks may or may not be in perfect sync. The transmission bit rate is linearly dependent on the frequency of the supplied clock signal. The relationship is described by: bitrate = f i 372 Where f i denotes the clock frequency of the signal used for the CLK line. As previously mentioned some smart cards have internal clock generators. In this case, the smart card bit rate is set to 9600bps. Only minor modifications to the code supplied with this application note are necessary to support cards with built in clock generators. 5

4 Hardware This application note provides firmware written for the XMEGA A1U Xplained Pro evaluation kit with an external smart card socket connected. The code will work with most of the XMEGA family and can be modified to run on any Atmel MCU with U(S)ART support, timer output capabilities, and optionally TWI/I 2 C support. The firmware is written with the hardware configurations suggested in Section 1.8 in mind. Alternatively the hardware configurations suggested in Figure 4-1 can be used to add support for class C (1.8V) devices. Figure 4-1. Power Supply with Support for Class B and C Smart Cards 4.1 Power Connections The hardware solution presented in Figure 4-1 will support both class B and C (3.0V and 1.8V) smart cards. Table 4-1 lists the different switch/selector configurations and the resulting smart card VCC values. Table 4-1. Different Switch/selector Configurations Resulting Smart Card VCC Values PD4 PD3 Smart card VCC Low Low 0V Low High 0V High Low 1.8V High High 3.0V 6

5 Interfacing the Reader The reader is configured with a TWI/I 2 C interface for communication with an interfacing application controller. The communication protocol relies on various control words for configuring the reader itself and communication with a connected smart card. 5.1 Addressing As listed in Table 5-1, the TWI/I 2 C device address is set to be 0x21. Taking the R/W bit in the TWI address into account gives the address 0x42 to write and 0x43 to read. Table 5-1. TWI/I 2 C Device Address Set to 0x21 TWI/I 2 C base address TWI/I 2 C write address TWI/I 2 C read address 0x21 0x42 0x43 5.2 Configuration Registers The reader has two configuration registers used for configuring the reader and the smart card interface. These registers can be configured using the TWI/I 2 C interface with the command listed in Table 5-2. Table 5-2. Command List Description Address Command Data byte 1 Data byte 2 Write configuration 0x42 (0b10<<6)+SC_CFG0 SC_CFG1 CFG_CHECK 7

5.2.1 SC_CFG0 Configuration Register 0 Bit 7 6 5 4 3 2 1 0 SC_CFG0 1 0 SHUTDOWN RETRY[2:0] VCARD[1:0] Access W W W W W W W W Reset 1 0 0 0 1 1 0 0 Bit [7:6] These bits are part of the command and must always be 0b10. Bit 5 SHUTDOWN This bit activates or deactivates the connected smart card according to the process described in the ISO7816 standard. SHUTDOWN Action 0 Activate the smart card according to ISO7816 after updating the configuration registers 1 Shutdown the smart card Bit [4:2] RETRY These bits define how many attempts should be made to retransmit a byte of data if NAK is received from the smart card. RETRY [4:2] 000 0 001 1 010 2 Number of retries 111 7 Bit [1:0] VCARD These bits configure the smart card reader pins according to the table listed in Section 4.1. With the circuitry proposed in Figure 4-1 or similar, these bits will define the voltage supplied to the connected smart card PWR pin. VCARD [1:0] Smart card voltage supply 00 0.0V (1) 01 1.8V (1) 10 3.0V (1) 11 Reserved for 5.0V operation Class A smart cards (2) Notes: 1. Voltage change will not take effect unless an activation is run. 2. This application note does not suggest hardware for class A smart cards, but this can be achieved with minor changes to the circuitry suggested in Figure 4-1. 8

5.2.2 SC_CFG1 Configuration Register 1 Bit 7 6 5 4 3 2 1 0 SC_CFG1 GUARD_TIME[6:0] CLOCK_SPEED[1:0] Access W W W W W W W W Reset 0 0 0 0 0 0 1 1 Bit [7:2] GUARD_TIME According to Section 3.4 additional guard time is needed after transmission for the receiver to ACK or NAK the transmission. The guard time can be adjusted using these bits. Setting these bits to zero gives a default guard time of 186µs, which is the recommended guard time for a 4MHz clock. The actual resulting guard time is given by: G t 4GUARD _ TIME 2.75s Where G t is the guard time in µs. To calculate the needed guard time, the etu or bit length of the signal must be known. The bit length for an asynchronous card with external clock is given by: etu 372 SC CLK Here SCCLK denotes the smart card clock frequency. The guard time Gt should be 2 etu. For a 4MHz clock this result in 186µs. Bit [1:0] CLOCK_SPEED These bits can be used to change the frequency of the clock provided to the smart card. CLOCK_SPEED [1:0] Clock signal on CLK pin 00 0MHz 01 1MHz 10 2MHz 11 4MHz 9

5.2.3 CFG_CHECK SC_CFG1 Bit 7 6 5 4 3 2 1 0 CFG_CHECK[7:0] Access W W W W W W W W Reset 0 0 0 0 0 0 0 0 Bit [7:0] CFG_CHECK This byte is used by the smart card reader to detect possible transmission errors in the received SC_CFG0 and SC_CFG1 packets sent to the reader over TWI/I 2 C. CFG_CHECK should equal a bitwise XOR between SC_CFG0 and SC_CFG1. If a transmission error is detected, the smart card connection will be deactivated. 10

5.3 Interface Register The interface register can be used to control the smart card reader GPIO pins, issue a reset signal to the smart card, or placing the reader in sleep mode. The register is write-only, and all bits will be cleared after the written command has been executed. 5.3.1 SC_INTERFACE Bit 7 6 5 4 3 2 1 0 SC_INTERFACE 0 IODIS CKSTOP CARDRST AUX SLEEP CARDCK CARDIO Access W W W W W W W W Reset 0 0 0 0 0 1 0 0 Bit 7 This bit is a part of the command, and must always be written to 0b0. Bit 6 IODIS This bit selects one out of two possible operation modes for the smart card interface pins: IODIS Action 0 The interface pins CLK, RST, and I/O will be driven as defined by the ISO7816 standard, and the CARDCK, CARDIO, and CARDRST bits are ignored 1 The smart card interface pins CLK, RST, and I/O are driven as defined by the CARDCK, CARDIO, and CARDRST bits Bit 5 CKSTOP This bit can be used to stop the smart card clock. Some smart cards will enter sleep mode when the clock is stopped. CKSTOP Action 0 No action 1 The smart card clock is stopped (1) Note: 1. If the smart card clock is stopped, the card must be reactivated according to the procedure described in Section 3.1. Bit 4 CARDRST The smart card reader response to setting this bit is dependent on the IODIS and the smart card reset mode detected during the activation process. The reset pulse length is defined in firmware with a default duration of 2ms. CARDRST IODIS Action 0 0 No action 1 RST line driven low 1 0 The smart card interface pins CLK, RST, and I/O are driven as defined by the CARDCK, CARDIO, and CARDRST bits 1 RST line driven high 11

Bit 3 AUX This bit controls the output level present at the AUX pin (PD5) after the output driver has been activated by setting IODIS at least once after powering the reader. AUX Action 0 PD5 is driven low 1 PD5 is driven high Note: The AUX pin driver is activated the first time IODIS is written to 1, therefore IODIS must be written at least once before the AUX pin can be driven as defined by the AUX bit. Bit 2 SLEEP If written to 1, the XMEGA enters sleep mode. The device will wake on TWI/I 2 C address match. A smart card deactivation is recommended before entering sleep mode. SLEEP Action 0 No action 1 The smart card reader enters sleep mode (1) Note: 1. It is recommended to deactivate the smart card before entering sleep mode. Bit 1 CARDCK If IODIS is set to 1 this bits controls the drive level of the smart card CLK line. CARDCK Action 0 CLK line is driven low (1) 1 CLK line is driven high (1) Note: 1. Only effective when IODIS is set to 1. Bit 0 CARDIO If IODIS is set to 1 this bit controls the drive level of the smart card I/O line. CARDIO Action 0 I/O line is driven low (1) 1 I/O line is driven high (1) Note: 1. Only effective when IODIS is set to 1. 12

5.4 Writing Data to the Smart Card When writing a data packet to the smart card, the TWI address 0x42 must be used. The first two data bytes should be the command byte 0xF8 and a byte declaring how many bytes there are in the data packet. Next number of actual data bytes follows directly. Description Address Command byte Data byte 1 Data byte 2 Data byte N Write data to smart card 0x42 11111000 (0xF8) Length (N) DATA0 DATAN Note: The smart card reader will store the received data in a 250-byte buffer until it gets time to process and send the data to the smart card. It is therefore important to keep the buffer size in mind when writing data to the smart card. 5.5 Reading Data from the Smart Card All data transmitted from a connected smart card to the smart card reader is stored in an internal receiver buffer. This data can be read by issuing a read command over the smart card reader TWI/I 2 C interface. The first byte returned after a read command will always be a status byte. Continuing reading the smart card reader will transmit data bytes until its internal buffer is emptied or the interfacing device NAKs a data byte. The data packet sent from the reader in response to the read command will be as listed below. Description Address Data byte 1 Data byte 2 Data byte 3 Data byte 4 Data byte 5 Data byte N Read data 0x43 SC_STATUS DATA1 DATA2 DATA3 DATA4 DATAN 13

5.5.1 SC_STATUS This byte contains information about the smart card and the smart card reader. Bit 7 6 5 4 3 2 1 0 SC_STATUS - DATA BUFFER_OVF NO_CMD NAK_CONF NAK PROTVIOL DATA_TO_SC Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 Reserved bit. Bit 6 DATA This bit is set if there is data in the smart card reader receiver buffer. Bit 5 BUFFER_OVF This bit is set if the smart card reader receiver buffer has overflown and lost data. Bit 4 NO_CMD This bit is set if the smart card reader has received an unknown command. If this happens the receiver buffer will be flushed. Bit 3 NAK_CONF The reader has received invalid configuration values. Bit 2 NAK The smart card has NAK d a byte more than the number of retries specified in SC_CFG0 RETRY. Bit 1 PROTVIOL This bit is set if the smart card reader communication protocol has been violated, e.g. the configuration check byte is incorrect. Bit 0 DATA_TO_SC This bit is set if there is data in the smart card reader transmit buffer waiting to be sent to a connected smart card. 5.6 Interface Summary Description Address Command byte Data byte 1 Data byte 2 Data byte N Write configuration 0x42 10+SC_CFG0 SC_CFG1 CFG_CHECK Write interface 0x42 0+SC_INTERFACE Write data to smart card 0x42 11111000 (0xF8) Length (N) DATA0 DATAN Read data from smart card 0x43 SC_STATUS DATA1 DATA2 DATAN 14

6 Interrupt Pin The smart card reader has an interrupt pin (PC5) used for signaling that the reader receiver buffer contains data waiting to be sent to the application processor. Connecting this pin is optional, but if left unconnected the smart card reader will be unable to signal when there is data in the receiver buffer, and the application processor will have to poll for data to avoid buffer overflows. The interrupt pin is low when the smart card reader receiver buffer is empty. If there is data in the receiver buffer the interrupt pin is driven high until the buffer is emptied. 7 Sleep Mode After power-on the smart card reader is put in the Power Down sleep mode to conserve energy. When the reader is in sleep mode all unused peripherals are turned off and all unused ports are pulled up to give them a defined state. Any address match on the TWI bus will bring the reader out of sleep and put it in idle mode, where it is ready to access a connected smart card. The reader can be put back to sleep using the SLEEP bit in the SC_INTERFACE register. It is recommended to deactivate any connected smart card before the reader is put in sleep mode as the smart card clock is stopped when the reader goes to sleep. 15

8 Revision History Doc Rev. Date Comments 42624A 11/2015 Initial document release. 16

Atmel Corporation 1600 Technology Drive, San Jose, CA 95110 USA T: (+1)(408) 441.0311 F: (+1)(408) 436.4200 www.atmel.com 2015 Atmel Corporation. / Rev.:. Atmel, Atmel logo and combinations thereof, AVR, Enabling Unlimited Possibilities, tinyavr, XMEGA, and others are registered trademarks or trademarks of Atmel Corporation in U.S. and other countries. ARM, ARM Connected logo, and others are the registered trademarks or trademarks of ARM Ltd. Other terms and product names may be trademarks of others. DISCLAIMER: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LI MITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATM EL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accurac y or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. SAFETY-CRITICAL, MILITARY, AND AUTOMOTIVE APPLICATIONS DISCLAIMER: Atmel products are not designed for and will not be used in connection with any applications wh ere the failure of such products would reasonably be expected to result in significant personal injury or death ( Safety -Critical Applications ) without an Atmel officer's specific written consent. Safety-Critical Applications include, without limitation, life support devices and systems, equipment or systems for the operation o f nuclear facilities and weapons systems. Atmel products are not designed nor intended for use in military or aerospace applications AVR1623: or environments XMEGA unless Smart specifically Card designated Reader by Atmel [APPLICATION as military-grade. Atmel NOTE] products are not designed nor intended for use in automotive applications unless specifically designated by Atmel as automotive-grade. 17