'---------------------------------------------------------------------------------------- ' Name: I2CL_DEMO_002.TIG ' Type: Tiger-BASIC(tm) Source Code ' Purpose: Introduction and demo for functions: "I2CL_xxxxx" ' ' I 2 C - Bus low level functions ' ' I S O 7 8 1 6 (Serial Chip Cards) ' ' (C) - Copyright 2002 Wilke Technology, P.O.Box 1727, D-52018 Aachen, Germany '---------------------------------------------------------------------------------------- ' ' Thank you for using BASIC Tigers in your products. If you have questions, ideas ' or special needs, please contact your next distributor or the Tiger support team ' and visit our web site: ' ' Wilke Technology GmbH ' The Tiger Support Team ' P.O.Box 1727, D-52018 Aachen, Germany ' Krefelder Str. 147, D-52070 Aachen, Germany ' ' email: support@wilke-technology.com (english) ' email: support@wilke.de (german) ' Phone: +49 (241) 918 900 Mo to Fr, 7:00 to 16:00 (GMT) ' Fax: +49 (241) 918 9068 ' ' New information, new drivers and free downloads see: ' ' www.wilke-technology.com (english) ' www.wilke.de (german) ' ' Sincerely, ' ' Your Tiger Support Team ' '---------------------------------------------------------------------------------------- ' ' This demo was compiled with Tiger-BASIC V5.01 / 1.12j or later to run on a ' Plug & Play Lab with a Tiger AXI-4/4. ' The bus lines used in this example program are: ' ' L80 = SCL = Clock (always generated by master) ' L81 = SDA = Data I/O (bidirectional) ' ' ' ' I2C-Bus / ISO 7816 Configuration Schematic: ' ============================================ ' ' !----------+-------- Vcc = +5V ' ! ! ' ! ! ' !---! !---! ' ! ! ! ! ' !------------------! ! R ! ! R ! ' ! BASIC-Tiger ! ! ! ! ! ' ! TINY-Tiger ! !---! !---! ' ! ECONO-Tiger ! ! ! ' ! ! ! ! ' ! SCL = CLOCK !-------+-------------------- I2C-Bus / ISO 7816 ' ! (L80) ! ! ' ! ! ! ' ! ! ! ' ! SDA = DATA !------------------+--------- I2C-Bus / ISO 7816 ' ! (L81) ! ' ! ! ' ! ! ' ! RST = Reset !----------- ISO 7816: Reset ADR-Counter ' ! ! ' ! ! This line (if needed) ' ! ! gets controlled by ' ! ! the BASIC program directly ' !------------------! ' See: ISO 7816 documentation ' Siemens SLE 4432, SLE 4442 etc. Chip Card documentation ' '---------------------------------------------------------------------------------------- ' ' Comparison between I2C and ISO 7816: ' ==================================== ' ' <------- I2C-Bus -------> <------- ISO 7816 -------> ' ' 1.) Bit sequence: MSB-first: LSB-first: ' ... ... ' ' 2.) bit: ... No bit used ' Receiving device confirms: ' Low => ACK, High => NAK ' ' 3.) Reset: Normally no reset line RST line used for resetting ' ADR counter ' ' ATR = Answer-to-Reset procedure ' is standardized through ISO 7816-3. ' '---------------------------------------------------------------------------------------- ' ' I2C-Bus Signals: ' =================== ' ' . Transmitter ' H ------! !-----!.. !-----!.................!-----------! !--------------- ' Data ! ! D7 ! ! D6 ! !reads ! ! ' Transm.! ! ! ! ! !of receiver! ! ' L (OUT) !-------!-----!...!-----!.................! !--------! ' . . ' . . ' H ---------------------------------------------------! Rec.!--------------------------- ' Data . ! Ack ! . ' Receiver. ! ! . ' L . !-----! . ' . . ' . Bit Bit Bit Ack . ' . 7 6 0 Nak . ' H ----------! !---! !---! !---! !---! !------------------- ' . ! ! 1 ! ! 2 ! ! 8 ! ! 9 ! ! . Clock always ' Clock . ! ! ! ! ! ! ! ! ! ! . generated by ' L . !----! !-----! !--... ...-! !-----! !--------! . MASTER device ' . ^ . ' . ! . ' . <- START Clock pulse . <- STOP ' condition for condition ' acknowledgement ' ' ' ' Example for a multi-byte communication: ' ' ' <-Master writing-> <----Master reading----> ' <7...0> <7...0> <7...0> ..... <7...0> ' ' Master: ======= ======= ======= === === ====== ' Slave: === === ======= ======= ' Transmitter: ======= ======= ======= ======= ' Receiver: === === === === ' '---------------------------------------------------------------------------------------- ' ' I S O 7 8 1 6 Signals: ' ============================= ' ' ' H ------! !-----!.. !-----!..........!-----! !----------------- ' Data ! ! D0 ! ! D1 ! ! D7 ! ! ' Transm.! ! ! ! ! ! ! ! ' L (OUT) !---------!-----!...!-----!..........!.....!-----------------! ' . . ' . . ' H ------------------------------------------------------------------------------------- ' Data . . ' Receiver. . ' L . . ' . . ' . Bit Bit Bit . ' . 0 1 7 . ' H ------------! !---! !---! !---! !----------------------- ' . ! ! 1 ! ! 2 ! ! 8 ! ! . Clock always ' Clock . ! ! ! ! ! ! ! ! . generated by ' L . !----! !-----! !--... ...-! !------------! . MASTER device ' . . ' . . ' . <- START . <- STOP ' condition condition ' '---------------------------------------------------------------------------------------- ' ' The new "Low Level" I2C-Bus functions consist of I2C-Bus components, that can be ' combined as needed to tailor the communication to different kinds of I2C-Bus devices. ' ' The components are: ' ' - Setup I2C-Bus ' - Set START condition on bus ' - Set STOP condition on bus ' - Write byte(s) ' - Read byte(s) ' ' Also, besides I2C-Bus communication, these functions support the ISO 7816 format ' as used in intelligent chip cards like Siemens SLE 4432 / 4442 and similar. ' ' ' "Low Level" I2C-Bus functions ' ' I2CL_SETUP (Port, Clock_Pin, Data_Pin, Speed_slow_down) ' ' = Port for CLOCK + DATA pins ' = Bit no: 0...7 for CLOCK pin ' = Bit no: 0...7 for DATA pin ' = Speed reduction: 1=no, 20=slower ' ' I2CL_START (0) ' Set START condition on bus lines, 0=dummy parameter ' I2CL_STOP (0) ' Set STOP condition on bus lines, 0=dummy parameter ' ' FLG = I2CL_WRITE (string$) ' Write all bytes of string to I2C-Bus ' FLG = I2CL_WRITE (num1, num2) ' Write bytes of to I2C-Bus ' ' num2 = 0,1,2,3,4, sequence is LSB first ' ' FLG = I2CL_WRITE (string$, 7816) ' As above, ISO-7816 bus, NO ' FLG = I2CL_WRITE (num1, num2, 7816) ' As above, ISO-7816 bus, NO ' ' A$ = I2CL_READ$ (nob) ' READ byte(s) from I2C-Bus with ACK bit ' A$ = I2CL_READ$ (nob, 7816) ' READ byte(s) from ISO-7816 bus ' ' ' FLG -> is the number of written bytes that received a from the device. ' '---------------------------------------------------------------------------------------- USER_VAR_STRICT ' Check for proper variable declaration ! LONG A, FLG, EVER ' Global variables STRING A$ ' '---------------------------------------------------------------------------------------- TASK MAIN ' Begin task MAIN ' (Port, Clock_Pin, Data_Pin, Speed_Reduction: 1=no ... 20=slower) I2CL_SETUP (8, 0, 1, 1) ' Setup I2C pins '---------------------------------------------------------------------------------------- ' Some examples of WRITE and READ functions. --> See I2C-chip manual for details ' as ADDR and control '---------------------------------------------------------------------------------------- FOR EVER = 0 TO 0 STEP 0 ' <--------------- Endless loop ----------------- I2CL_START (0) ' Set START-Condition on Bus FLG = I2CL_WRITE ("55 F0"%, 7816) ' Write all bytes of string to I2C-Bus FLG = I2CL_WRITE ("55 F0"%) ' Write all bytes of string conform to ISO 7816 A = 12345678H ' LONG value for output FLG = I2CL_WRITE (A, 0, 7816) ' Write ISO 7816: nothing FLG = I2CL_WRITE (A, 1, 7816) ' Write ISO 7816: 1 byte of LONG A starting with LSB FLG = I2CL_WRITE (A, 2 ) ' Write I2C-Bus: 2 bytes of LONG A starting with MSB FLG = I2CL_WRITE (A, 3, 7816) ' Write ISO 7816: 3 bytes of LONG A starting with LSB FLG = I2CL_WRITE (A, 4, 7816) ' Write ISO 7816: 4 bytes of LONG A starting with LSB FLG = I2CL_WRITE (A, 5 ) ' Write I2C-Bus: 4 bytes of LONG A starting with MSB I2CL_STOP (0) ' Set STOP condition on bus WAIT_DURATION 200 ' Wait 200 ms I2CL_START (0) ' Set START condition on bus A$ = I2CL_READ$ (8) ' READ 8 bytes from I2C-Bus A$ = I2CL_READ$ (4, 7816) ' READ 4 bytes from ISO 7816 A$ = I2CL_READ$ (4, 7) ' READ 4 bytes from I2C-Bus A$ = I2CL_READ$ (4) ' READ 4 bytes from I2C-Bus A$ = I2CL_READ$ (0) ' READ 0 bytes from I2C-Bus I2CL_STOP (0) ' Set STOP condition on bus WAIT_DURATION 200 ' Wait 200 ms NEXT ' ------------ End of endless loop -------------> END ' End of task MAIN