本帖最后由 qq5782098 于 2018-1-15 15:47 编辑
智能卡(CPU卡)接受不到过程字节。
有一张CPU卡发送选择文件命令 00 A4 00 00 02 3F 00接到不到过程字节和任何数据
但是发送随机数命令 00 84 00 00 02可以正常获取并得到随机数。
代码
unsigned int ICC_IsoCommand(int p_iInLength, unsigned char *p_abSentData, unsigned char *p_iOutLen, unsigned char *p_abResponse)
{
// Local variable declaration
unsigned char ACK = 0;
unsigned int l_wStatus = 0;
int i; //for counter
unsigned char p_bIsoType = 0;
unsigned char Status = 0; //调试完去掉
//ICC_ChangeSlot(Slot);
//USART_DMACmd(SC_USART, USART_DMAReq_Rx, ENABLE);
// Send command
if(USART_GetFlagStatus(CPU_USARTx, USART_FLAG_RXNE) == SET) //经调试需要在此家一个 读操作来过滤上电的一个字节 复位同理
{
USART_ReceiveData(CPU_USARTx);
}
WritesamData(&p_abSentData[CMD_CLA]);
WritesamData(&p_abSentData[CMD_INS]);
WritesamData(&p_abSentData[CMD_P1]);
WritesamData(&p_abSentData[CMD_P2]);
WritesamData(&p_abSentData[CMD_P3]);
Status = USART_ReceiveData(CPU_USARTx);
if(p_iInLength==0x05)
{
p_bIsoType=ISO_OUT; //case 2
p_iOutLen[0]=p_abSentData[CMD_P3];
}
else
{
p_bIsoType=ISO_IN; //case 3
p_iOutLen[0]=0x00;
}
ReceiveGoOn:
if(ReadPsamData(&ACK, SC_Receive_Timeout)==0)
{
return 0x6fff;
}
if (ACK == 0x60)
{
goto ReceiveGoOn;
}
if (ACK != p_abSentData[CMD_INS])
{
l_wStatus = (ACK<<8);
if(ReadPsamData(&ACK, SC_Receive_Timeout)==0)
{
//p_iOutLen[0]=0x00;
return 0x6fff;
}
l_wStatus = l_wStatus | ACK;
return l_wStatus;
}
switch (p_bIsoType)
{
case ISO_IN : //case 3
CardDelay_ms(1);
// Send buffer data
for (i = 0; i < (p_iInLength-5) ; i++)
{
WritesamData(&p_abSentData[i+5]);
}
(void)USART_ReceiveData(CPU_USARTx);
l_wStatus = GetStatus();
return l_wStatus;
case ISO_OUT : //case 2
for (i = 0; i < p_iOutLen[0]; i++)
{
if(ReadPsamData(&ACK,SC_Receive_Timeout)==0)
{
//p_iOutLen[0]=0x00;
return 0x6fff;
}
p_abResponse = ACK;
}
l_wStatus = GetStatus();
return l_wStatus;
default : //p_iOutLen[0]=0x00;
return(0x6fff);
}
}
|