• AVR Freaks

LockedTX/RX on the same line (Smartcard)

Page: 12 > Showing page 1 of 2
Author
xfiles_2007
Junior Member
  • Total Posts : 93
  • Reward points : 0
  • Joined: 2016/04/21 05:19:37
  • Location: 0
  • Status: offline
2016/10/18 05:42:46 (permalink)
0

TX/RX on the same line (Smartcard)

Hi,
 
Im trying to communicate with a smart card but the I/O is just one line.
 
How do i connect the smart card I/O this to a PIC16628a chips TX/RX ? I see some documentation online and I've put a 4K7 resistor, however something is not right when using the UART. Do I need something else in between ? (http://ww1.microchip.com/downloads/en/AppNotes/01370A.pdf)
 
Now if i have a different input source (not a smart card) then i can receive and submit bytes as expected, so the UART module seems to work when theres 2 different wires.... just don't know what to do with a one line I/O smart card.
 
How do I force the TX disabled while it should be receiving ? Is this possible.
 
 
Thanks!
 
 
 
 
 
 
 
 
 
#1

23 Replies Related Threads

    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/18 06:04:33 (permalink)
    0
    I'd do that in software and not use the HW USART ... so you have full control over the pins.
    I did that, many years ago!

    GENOVA :D :D ! GODO
    #2
    TJ2015
    The New Math
    • Total Posts : 491
    • Reward points : 0
    • Joined: 2015/04/19 11:38:37
    • Location: OSI
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/18 06:13:19 (permalink)
    +1 (1)
    You have to manage this in your software.
     
    This is nothing more than standard half duplex synchronous serial communication protocol, there should be some app notes somewhere.
    #3
    jack@kksound
    code tags!
    • Total Posts : 3227
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/18 09:35:01 (permalink)
    0
    Microchip MLA (Legacy versions) provided Smart Card library functions, you may find some help there.
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 18901
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: TX/RX on the same line (Smartcard) 2016/10/18 10:19:45 (permalink)
    +1 (1)
    PIC16F628a I assume.
    DS40044G-page 73
    TXSTA register  TXEN bit
    You may want a series resistor to limit the current if they both transmit.
    You can also do this with an external chip, or maybe a series diode.
    #5
    jack@kksound
    code tags!
    • Total Posts : 3227
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/18 11:23:42 (permalink)
    +1 (1)
    TJ2015
    You have to manage this in your software.
     
    This is nothing more than standard half duplex synchronous serial communication protocol, there should be some app notes somewhere.


    I am not sure this is synchronous serial, the clock signal provided to the smart card is either 3.579545 Mhz (US)  or 4.9152 Mhz (EU). This is internally divided to produce a 9600 baud serial link. The protocol is 10 bit serial, with a start bit, 8 data bits and a parity bit: Asynchronous serial (UART) on a single I/O line.
    You must control the TX output as pointed out by NKurzman using the TXEN bit to enable and disable the transmitter.
    NKurzman
    PIC16F628a I assume.
    DS40044G-page 73
    TXSTA register  TXEN bit
    You may want a series resistor to limit the current if they both transmit.
    You can also do this with an external chip, or maybe a series diode.




    #6
    xfiles_2007
    Junior Member
    • Total Posts : 93
    • Reward points : 0
    • Joined: 2016/04/21 05:19:37
    • Location: 0
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/18 18:57:56 (permalink)
    +1 (1)
    Thanks all.
     
    Im going to try by disabling the transmission TXEN after a transmission..
     
     
    #7
    TJ2015
    The New Math
    • Total Posts : 491
    • Reward points : 0
    • Joined: 2015/04/19 11:38:37
    • Location: OSI
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/19 06:18:53 (permalink)
    0
    jack@kksound
    TJ2015
    You have to manage this in your software.
     
    This is nothing more than standard half duplex synchronous serial communication protocol, there should be some app notes somewhere.


    I am not sure this is synchronous serial, the clock signal provided to the smart card is either 3.579545 Mhz (US)  or 4.9152 Mhz (EU). This is internally divided to produce a 9600 baud serial link. The protocol is 10 bit serial, with a start bit, 8 data bits and a parity bit: Asynchronous serial (UART) on a single I/O line.
    You must control the TX output as pointed out by NKurzman using the TXEN bit to enable and disable the transmitter.
    NKurzman
    PIC16F628a I assume.
    DS40044G-page 73
    TXSTA register  TXEN bit
    You may want a series resistor to limit the current if they both transmit.
    You can also do this with an external chip, or maybe a series diode.






    You are correct, I misinterpreted what I was looking at.
     
    After reading more about I see that it is asynchronous.
    #8
    jack@kksound
    code tags!
    • Total Posts : 3227
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/19 08:39:38 (permalink)
    +1 (1)
    Yep, there is an app note that discusses the SmartCard protocols: AN1370. And the legacy MLA has example code for it.
    #9
    xfiles_2007
    Junior Member
    • Total Posts : 93
    • Reward points : 0
    • Joined: 2016/04/21 05:19:37
    • Location: 0
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/19 21:44:49 (permalink)
    0
    No luck with this... I disabled TXEN when receiving but still not getting any input after sending out some bytes.
     
    i have a 4k7 resistor in between the TX and RX on the PIC (which goes to the card I/O line)
     
     
     
    #10
    NKurzman
    A Guy on the Net
    • Total Posts : 18901
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: TX/RX on the same line (Smartcard) 2016/10/19 21:51:15 (permalink)
    0
    Why such a large resistor?
    Why one at all?
    Disabling Tx will return control of the pin to tris. Is tris set as an input?

    Leave connect rx and tx with a 100 ohm resistor. And rx to the card.
    Do you have a scope? Is the card getting the message and trying to respond?
    #11
    qhb
    Superb Member
    • Total Posts : 9999
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/19 22:37:58 (permalink)
    +1 (1)
    xfiles_2007
    No luck with this... I disabled TXEN when receiving but still not getting any input after sending out some bytes.

    WHEN exactly are you disabling TXEN?
    You have to wait for TXIF and TRMT to both be set, to indicate all the transmission has finished.
    (Even then, it is still sending the stop bit for the last character, so a small delay can be useful. i.e. for one bit time.)
    #12
    xfiles_2007
    Junior Member
    • Total Posts : 93
    • Reward points : 0
    • Joined: 2016/04/21 05:19:37
    • Location: 0
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/19 22:49:16 (permalink)
    0
    @NKurzman just followed the diagram on the documentation which had 4k7 . Im trying this with the HW UART module. On the logic analyser i can see the outgoing bytes as expected, its not responding.
     
    @qhb disabling after the putch, function (HW UART) is complete. Ill try a delay.
     
     
     
    #13
    qhb
    Superb Member
    • Total Posts : 9999
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/19 22:56:17 (permalink)
    +1 (1)
    xfiles_2007
    ...
    @qhb disabling after the putch, function (HW UART) is complete. Ill try a delay.
     

    If your putch() function has been implemented the standard way (i.e. by polling TXIF), then it will return BEFORE the character has been transmitted.
    This is normally desirable, but you must be aware of it when implementing a half-duplex link.
     
    #14
    xfiles_2007
    Junior Member
    • Total Posts : 93
    • Reward points : 0
    • Joined: 2016/04/21 05:19:37
    • Location: 0
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/19 23:07:23 (permalink)
    0
    @qhb this has been a long struggle lol... heres my putch function. ill try a one bit delay.
     
    void putch(unsigned char byte) {
    /* output one byte */
     
    while(!TXIF) /* set when register is empty */
    continue;
    TX9D = parity;
    TXREG = byte;
     

    }
    #15
    qhb
    Superb Member
    • Total Posts : 9999
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/20 01:52:22 (permalink)
    +1 (1)
    A one bit delay won't be enough if you have not already waited for TXIF and TRMT to both be high, AFTER writing to TXREG.
    Otherwise you would need a 20 bit delay to be sure!
    #16
    NKurzman
    A Guy on the Net
    • Total Posts : 18901
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: TX/RX on the same line (Smartcard) 2016/10/20 05:44:56 (permalink)
    +1 (1)
    Is you 4.7k resistor between the tx and the smart card?
    If so you should see the response on the smart card side of the resistor. Even if the tx is enabled. If not the baud rate is wrong or the message content is wrong.
    #17
    xfiles_2007
    Junior Member
    • Total Posts : 93
    • Reward points : 0
    • Joined: 2016/04/21 05:19:37
    • Location: 0
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/20 07:14:44 (permalink)
    +1 (1)
    awesome! i can now see the data coming back from the smart card to the PIC after disabling TXEN (via a logic analyser)
     
    but..... the PIC doesn't seem to react to the incoming byte, it seems to be stuck in a loop somewhere. 
     
    Do i need to clear any rx registers after disabling TXEN ?
     
    Im using the HW UART modules.
     
     
    #18
    jack@kksound
    code tags!
    • Total Posts : 3227
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: TX/RX on the same line (Smartcard) 2016/10/20 09:55:35 (permalink)
    +2 (2)
    If the UART receiver indicates an overflow error (OERR) then the receiver is disabled until it is reset. Are you handling this possibility in your receive functions?
    #19
    NKurzman
    A Guy on the Net
    • Total Posts : 18901
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: TX/RX on the same line (Smartcard) 2016/10/20 13:43:41 (permalink)
    +2 (2)
    As you send each byte if the receiver is on then it will hear them.  You must remove these bytes from the buffer as they arrive.
    Or you get an overflow error.
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5