need help for read and write smart card

Discussion in 'Embedded Systems and Microcontrollers' started by erickoh1985, May 8, 2008.

  1. erickoh1985

    Thread Starter New Member

    Feb 28, 2008
    7
    0
    i have a problem in read and write smart card with using PIC16F887 chip.
    My smart card model is ST14C02C.
    The datasheet can be find at http://www.datasheetcatalog.com/datasheets_pdf/S/T/1/4/ST14C02C.shtml
    Since i do not have any sample code for this smart card, so i have try to modified some other I2C EEPROM's source code, but it does not work with my smart card.
    Below is my circuit and source code.

    #include <16F887.h>
    #include <stdio.h>
    #fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP
    #use delay(clock=4000000)
    #use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7)
    #define EEPROM_SDA PIN_C4
    #define EEPROM_SCL PIN_C3
    #include <2402.c> // EEPROM driver
    #define hi(x) (*(&x+1))

    //-----------------------------------
    void write_word(int16 address, int16 data)
    {
    init_ext_eeprom();
    write_ext_eeprom(address, data); // Write LSB
    write_ext_eeprom(address+1, data >> 8); // Write MSB
    }

    //----------------------------------
    int16 read_word(int16 address)
    {
    int16 retval;
    init_ext_eeprom();
    retval = read_ext_eeprom(address); // Read LSB
    hi(retval) = read_ext_eeprom(address +1); // Read MSB
    return(retval);
    }
    //----------------------------------

    void main()
    {
    int8 data =0x02;
    int16 address =0x19;
    int16 value;
    printf("Hello");
    while (true)
    {
    write_word(address, data);
    value = read_word(address);
    if (value==0x02)
    {
    printf("value read = %ld \n\r", value);
    }
    }
    }

    circuit diagram link: http://www.imagehosting.com/show.php/1742009_1.JPG.html
    In the circuit diagram, 24C02B is an I2C EEPROM
    Hope can get some advice from you guys. Thanks.
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Reformatted for readability.

    hgmjr
     
  3. Papabravo

    Expert

    Feb 24, 2006
    10,138
    1,789
    What do your waveforms look like on an oscilliscope? Can you get the device to give you an ACK pulse? What address is the device wired for and where do you set the device address in your code?
     
Loading...