OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3246|回复: 1

基于RC531的TYPE B读卡器开发,无法寻找身份证

[复制链接]

5

主题

18

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
325
金钱
325
注册时间
2016-5-24
在线时间
74 小时
发表于 2016-7-28 17:55:12 | 显示全部楼层 |阅读模式
10金钱
我用rc531寻不到身份证,求大神帮我看一下那里出的问题?



do{

                        status = M531PiccRequestB(0, 0, 0, &g_cReceBuf[0]);//Ѱ¿¨                                                          
                  
        }
        while(status);
char M531PiccRequestB(u8 req_code,
                      u8 AFI,
                      u8 N,
                      u8 *ATQB)
{
    char  status;
    struct TranSciveBuffer MfComData;
    struct TranSciveBuffer *pi;
    pi=&MfComData;

    ClearBitMask(RegControl,0x08);      // disable crypto 1 unit   

     //SetBitMask(RegTxControl,0x03);      // Tx2RF-En, Tx1RF-En enable

    PcdSetTmo(5);
    MfComData.MfCommand = PCD_TRANSCEIVE;
    MfComData.MfLength  = 3;
    MfComData.MfData[0] = ISO14443B_ANTICOLLISION;                    // APf code
    MfComData.MfData[1] = AFI;                //
    MfComData.MfData[2] = ((req_code<<3)&0x08) | (N&0x07);  // PARAM

    status = PcdComTransceive(pi);

    if (status!=MI_OK && status!=MI_NOTAGERR)
    {   status = MI_COLLERR;   }

    if (MfComData.MfLength != 96)
    {   status = MI_COM_ERR;   }

    if (status == MI_OK)
    {       
            memcpy(ATQB, &MfComData.MfData[0], 16);
        PcdSetTmo(ATQB[11]>>4); // set FWT
    }        
    return status;
}                     
char PcdComTransceive(struct TranSciveBuffer *pi)
{
   char recebyte = 0;
   char status;
   u8 irqEn   = 0x00;
   u8 waitFor = 0x00;
   u8 lastBits;
   u8 n;
   u16 i;
   switch (pi->MfCommand)
   {
      case PCD_IDLE:
         irqEn   = 0x00;
         waitFor = 0x00;
         break;
      case PCD_WRITEE2:
         irqEn   = 0x11;
         waitFor = 0x10;
         break;
      case PCD_READE2:
         irqEn   = 0x07;
         waitFor = 0x04;
         recebyte=1;
         break;
      case PCD_LOADCONFIG:
      case PCD_LOADKEYE2:
      case PCD_AUTHENT1:
         irqEn   = 0x05;
         waitFor = 0x04;
         break;
      case PCD_CALCCRC:
         irqEn   = 0x11;
         waitFor = 0x10;
         break;
      case PCD_AUTHENT2:
         irqEn   = 0x04;
         waitFor = 0x04;
         break;
      case PCD_RECEIVE:
         irqEn   = 0x06;
         waitFor = 0x04;
         recebyte=1;
         break;
      case PCD_LOADKEY:
         irqEn   = 0x05;
         waitFor = 0x04;
         break;
      case PCD_TRANSMIT:
         irqEn   = 0x05;
         waitFor = 0x04;
         break;
      case PCD_TRANSCEIVE:
         irqEn   = 0x3D;
         waitFor = 0x04;
         recebyte=1;
         break;
      default:
         pi->MfCommand = MI_UNKNOWN_COMMAND;
         break;
   }

   if (pi->MfCommand!= MI_UNKNOWN_COMMAND)
   {
      WriteRawRC(RegPage,0x00);
      WriteRawRC(RegInterruptEn,0x7F);
      WriteRawRC(RegInterruptRq,0x7F);
      WriteRawRC(RegCommand,PCD_IDLE);
      SetBitMask(RegControl,0x01);
      WriteRawRC(RegInterruptEn,irqEn|0x80);
                 
               
      for (i=0; i<pi->MfLength; i++)
      {
         WriteRawRC(RegFIFOData, pi->MfData[i]);
                                delay_us(100);
      }
                       
      WriteRawRC(RegCommand, pi->MfCommand);
                        delay_us(100);
               
      i = 0x3500;
      do
      {
         n = ReadRawRC(RegInterruptRq);
                                delay_us(100);
         i--;
      }
      while ((i!=0) && !(n&irqEn&0x20) && !(n&waitFor));
      status = MI_COM_ERR;
      if ((i!=0) && !(n&irqEn&0x20))
      {
         if (!(ReadRawRC(RegErrorFlag)&0x17))
         {
            status = MI_OK;
            if (recebyte)
            {
                      n = ReadRawRC(RegFIFOLength);
                      lastBits = ReadRawRC(RegSecondaryStatus) & 0x07;
                if (lastBits)
                {
                   pi->MfLength = (n-1)*8 + lastBits;
                }
                else
                {
                   pi->MfLength = n*8;
                }
                if (n == 0)
                {
                   n = 1;
                }
                for (i=0; i<n; i++)
                {
                    pi->MfData[i] = ReadRawRC(RegFIFOData);
                                                                        delay_us(100);
                }
            }
         }
                 else if (ReadRawRC(RegErrorFlag)&0x01)
         {
                    status = MI_COLLERR;
            if (recebyte)
            {
                      n = ReadRawRC(RegFIFOLength);
                      lastBits = ReadRawRC(RegSecondaryStatus) & 0x07;
                if (lastBits)
                {
                   pi->MfLength = (n-1)*8 + lastBits;
                }
                else
                {
                   pi->MfLength = n*8;
                }
                if (n == 0)
                {
                   n = 1;
                }
                for (i=0; i<n; i++)
                {
                    pi->MfData[i+1] = ReadRawRC(RegFIFOData);
                                                                        delay_us(100);
                }
            }
                        pi->MfData[0]=ReadRawRC(0x0B);
         }

   }
      else if (n & irqEn & 0x20)
      {   status = MI_NOTAGERR;   }
      else if (!(ReadRawRC(RegErrorFlag)&0x17))
      {   status = MI_ACCESSTIMEOUT;   }
      else
      {   status = MI_COM_ERR;    }

      WriteRawRC(RegInterruptEn,0x7F);
      WriteRawRC(RegInterruptRq,0x7F);
      SetBitMask(RegControl,0x04);           // stop timer now
      WriteRawRC(RegCommand,PCD_IDLE);
   }
   return status;
}

else if (type == 'B')
   {
                 
                     u8 temp;
      ClearBitMask(RegControl,0x08);

       WriteRawRC(RegClockQControl,0x0);
       WriteRawRC(RegClockQControl,0x40);
       delay_us(100);  
       ClearBitMask(RegClockQControl,0x40);

       WriteRawRC(RegTxControl,0x4B);
       WriteRawRC(RegCwConductance,0x17);
       WriteRawRC(RegModConductance,0x06);      
       WriteRawRC(RegCoderControl,0x20);
       WriteRawRC(RegModWidth,0x13);            
       WriteRawRC(RegModWidthSOF,0x3F);         
       WriteRawRC(RegTypeBFraming,0x3B);

       WriteRawRC(RegRxControl1,0x73);
       WriteRawRC(RegDecoderControl,0x19);
       WriteRawRC(RegBitPhase,0xAD);       
       WriteRawRC(RegRxThreshold,0x88);
       WriteRawRC(RegBPSKDemControl,0x7E);
       WriteRawRC(RegRxControl2,0x01);

       WriteRawRC(RegRxWait,0x06);
       WriteRawRC(RegChannelRedundancy,0x2C);   
       WriteRawRC(RegCRCPresetLSB,0xFF);
       WriteRawRC(RegCRCPresetMSB,0xFF);
       WriteRawRC(RegTimeSlotPeriod,0x00);
       WriteRawRC(RegMfOutSelect,0x00);
       WriteRawRC(RFU27,0x00);                

       WriteRawRC(RegFIFOLevel,0x3F);
       WriteRawRC(RegTimerClock,0x07);
       WriteRawRC(RegTimerReload,0x0A);
       WriteRawRC(RegTimerControl,0x06);  
       WriteRawRC(RegIRqPinConfig,0x02);      
       WriteRawRC(RFU2E,0x00);
       WriteRawRC(RFU2F,0x00);
      PcdSetTmo(106);
       delay_ms(1);
       PcdAntennaOn();
   }


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2016-7-29 20:50:40 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-13 15:29

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表