Can't get APDU respond with single GPIO simulate half-duplex uart
Hi All,
here is the specific circumstances of my case:
1) Sim Card connect with TDA8024TT and CPU connect with I/0UC of TDA8024 by single GPIO. So i need use gpio simulate uart by delay and then send command to card following 7816 standard.
2) i can get the following ATR:
0x3b : 0x3d : 0x94 : 0x0 : 0x25 : 0xe :0x1 :0x36 :0x0 :0x0 :0x86 :0x60 :0x35 :0x0 :0x80 :0x12 : 0x7...
3) send PTS to Sim Card and get correct respond(as same as PTS request).==>> 0xff, 0x10, 0x94, 0x7b
question a: and when send last byte 0x7b,i find that if delay more than 6 etu i can't get correct respond.
4) finally, i send APDU command to Sim Card but can't get any respond==>> 0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7f, 0x20.and the following the my Pseudo code.
question b: why i can get respond of APDU?
1,active sim card and get ATR success(use default Fi Di ==>> 372 and 1,clk = 3.125MHZ, 1 etu = 119 us)
2,delay 20 etu
3,send PTS request function and get success respond(still use default Fi Di ==>> 372 and 1, 1 etu = 119 us)
void PTS_request()
{
uart_send(0xff);
delay(5 etu);
uart_send(0x10);
delay(5 etu);
uart_send(0x94);
delay(5 etu);
uart_send(0x7B);
delay(3 etu);
buf[0] = uart_recv();
buf[1] = uart_recv();
buf[2] = uart_recv();
buf[3] = uart_recv();
}
4, delay 10ms
5,send APDU command
void pc_to_sim_test()
{
uart_send(0xa0);
delay(2 etu);
uart_send(0xa4);
delay(2 etu);
uart_send(0x00);
delay(2 etu);
uart_send(0x00);
delay(2 etu);
uart_send(0x02);
delay(2 etu);
uart_send(0x7f);
delay(2 etu);
uart_send(0x20);
delay(2 etu);
buf[0] = uart_recv();
buf[1] = uart_recv();
}
6,uart_send function with gpio simulate
uart_send(unsigned char buf)
{
ecc = eve_check(buf);
//send start bit
set_low(gpio);
udelay(1 etu);
send(buf);// lower bit first and just like==>> set_high(gpio);udelay(1etu);set_low(gpio);udelay(1etu);...
//send parity bit
if(ecc)
set_high(gpio);
else
set_low(gpio);
udelay(1 etu);
//send stop bit
set_high(gpio);
udelay(1 etu);
}