我用STM32F103C8T6读取SIM卡,前面都没问题,就是这个地方
static uint8_t SC_decode_Answer2reset(uint8_t *card)
{
uint32_t i = 0, flag = 0, buf = 0, protocol = 0;
SC_A2R.TS = card[0]; /* Initial character */ //0X3B
SC_A2R.T0 = card[1]; /* Format character */ //0X1A
SC_A2R.Hlength = SC_A2R.T0 & (uint8_t)0x0F;
if ((SC_A2R.T0 & (uint8_t)0x80) == 0x80)
{
flag = 1;
}
for (i = 0; i < 4; i++)
{
SC_A2R.Tlength = SC_A2R.Tlength + (((SC_A2R.T0 & (uint8_t)0xF0) >> (4 + i)) & (uint8_t)0x1);
}
///////////////////
for (i = 0; i < SC_A2R.Tlength; i++)
{
SC_A2R.T = card[i + 2];
}
protocol = SC_A2R.T[SC_A2R.Tlength - 1] & (uint8_t)0x0F; //这个地方计算出protocol=0x01,可是=0x00才是T0协议。
USART_SendData(USART1,protocol );
for(ii=3000;ii>0;ii--);
while (flag)
{
if ((SC_A2R.T[SC_A2R.Tlength - 1] & (uint8_t)0x80) == 0x80)
{
flag = 1;
}
else
{
flag = 0;
}
buf = SC_A2R.Tlength;
SC_A2R.Tlength = 0;
for (i = 0; i < 4; i++)
{
SC_A2R.Tlength = SC_A2R.Tlength + (((SC_A2R.T[buf - 1] & (uint8_t)0xF0) >> (4 + i)) & (uint8_t)0x1);
}
for (i = 0;i < SC_A2R.Tlength; i++)
{
SC_A2R.T[buf + i] = card[i + 2 + buf];
}
SC_A2R.Tlength += (uint8_t)buf;
}
for (i = 0; i < SC_A2R.Hlength; i++)
{
SC_A2R.H = card[i + 2 + SC_A2R.Tlength];
}
return (uint8_t)protocol;
}
前面发帖子已经证明就是T0协议,可是为什么译码后是0x01呢?请问大神,哪里出错了?谢谢!
|