Shop OBEX P1 Docs P2 Docs Learn Events
Still working on Smart Card sample. — Parallax Forums

Still working on Smart Card sample.

karlprescottkarlprescott Posts: 15
edited 2012-05-06 05:44 in Propeller 1
Hi Guys,

I am working on the Smart Card demo (24c16 Demo). I am able to read data from the card but I am having trouble understanding the Write principle.
" sc.writeLocation(CLK, DeviceAddr | (((page) - 1) << 1) & 10, MAddr, char) "

I just get random data on the card when I change different values in the code.

Is their any one out there who fully understands it? I have looked at Jon Macs demo (jm_sc32322_Demo) and read both the Smart Card and Card Reader documentation and still dont get it.

Thanks for reading!

Karl

Comments

  • JonnyMacJonnyMac Posts: 9,195
    edited 2012-04-21 13:25
    I do! ;)

    This is the working code from my object:
    pub putpage(addr, n, src) | id, ackbit
    
    '' Write n bytes from src to Smart Card
    '' -- addr : address (0 to LAST_ADDR)     
    '' --    n : bytes to write
    '' --  src : pointer to source valuee
    ''
    '' Be mindful of address/page size in device to prevent page wrap-around
    
      if (addr => 0) and ((addr + n-1) =< LAST_ADDR)
        id := $A0 | ((addr >> 7) & %1110)                           ' create id with block address
        wait(id)                                                    ' wait for device
        write(addr & $FF)                                           ' write byte address
        ackbit := ACK                                               ' assume okay
        repeat (n #> 1)                                                    
          ackbit |= write(byte[src++])                              ' write a byte 
        stop
        
      else
        ackbit := NAK
        
      return ackbit
    

    What you're not seeing is that the EEPROM is setup as multiple blocks (documentation: http://ww1.microchip.com/downloads/en/devicedoc/21703g.pdf); the block derived from the address you want to write to and moved into the slave id. Each block is 256 bytes (bits 7..0 in the address) so the block number you want to access is held in bits 8 and higher. The reason my code only slides the bits over by 7 (instead of 8) is that bit0 of the SlaveID is for read/write control.

    Think of the address this way: %000_00000000. The upper three bits are the block #, the lower eight bits are the address within that block.

    I have to admit, this is a first. Most people just want to know where an object is and couldn't give two hoots about how it works. Good on you for wanting to know.
  • karlprescottkarlprescott Posts: 15
    edited 2012-04-22 13:09
    Hi Jon,
    Ive read that document you sent me and it make the process of writing easier to understand.

    I am using IS24C02_16A.spin as my object and that uses the writeLocation object. writeLocation(CLK, DeviceAddress, Register, Value)

    Can a decimal number (0-254) just be sent to a speciafic location say Page 0 Word Address 01?
  • karlprescottkarlprescott Posts: 15
    edited 2012-05-06 05:44
    Hi Jon,

    Got it working.. When I looked at your code it started working perfectly. Its the sample that paralax supply for the card that was giving me garbage. Wish I has looked at your code sooner.

    Thanks Karl :-)
Sign In or Register to comment.