RT,直接切入正题目前在做一个RC500 IC卡读写器
本人很水,看到64个寄存器和来回嵌套的程序调用就萎了
后面在网上DOWN了一个程序,改了一下后测试,发现能用
RC500能起振,TX1和TX2也有波形。
初始化通过。
可是在给寻卡命令的时候,却卡在超时那一块了。
以本人有限水平Debug到了问题出在这里:
do
{
sond=0;
n = ReadRawRC(RegInterruptRq);//当定时器TimerValue 寄存器值减为0 时置位
i--; sond=1;
}
while ((i!=0) && !(n&irqEn&0x20) && !(n&waitFor));
这里RegInterruptRq貌似定时器没有减为0,所以没有置位,所以一直超时
找了2天也没找到这个定时器是在什么情况下才递减。
无奈,所以特地来万能的坛求助,希望各位做过的大神帮帮小弟,度过这个难关,小弟不胜感激。
下面贴出那段程序,如果有必要我也可以贴出全部程序,就是不知道怎么贴。。。。
/////////////////////////////////////////////////////////////////////
//通过RC500和ISO14443卡通讯
//input: pi->MfCommand = RC500命令字
// pi->MfLength = 发送的数据长度
// pi->MfData[] = 发送数据
//output:status = 错误字
// pi->MfLength = 接收的数据BIT长度
// pi->MfData[] = 接收数据
/////////////////////////////////////////////////////////////////////
char PcdComTransceive(struct TranSciveBuffer *pi)
{
bit recebyte = 0;
char status;
unsigned char irqEn = 0x00;
unsigned char waitFor = 0x00;
unsigned char lastBits;
unsigned char n;
unsigned int 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);
//清除Command寄存器
SetBitMask(RegControl,0x01);
//清除FIFO指针
WriteRawRC(RegInterruptEn,irqEn|0x80);
for (i=0; i<pi->MfLength; i++)
{
WriteRawRC(RegFIFOData, pi->MfData[i]);//将数据写入FIFO
}
WriteRawRC(RegCommand, pi->MfCommand);//将指令写入Command寄存器
i = 0x8500;
do
{
sond=0;
n = ReadRawRC(RegInterruptRq);//当定时器TimerValue 寄存器值减为0 时置位
i--; sond=1;
}
while ((i!=0) && !(n&irqEn&0x20) && !(n&waitFor));
status = MI_COM_ERR;
//sond=0; AAA=0x01;
if ((i!=0) && !(n&irqEn&0x20))
{
if (!(ReadRawRC(RegErrorFlag)&0x17))
{
status = MI_OK;
if (recebyte) //从PICC读数据
{
n = ReadRawRC(RegFIFOLength);//指示保存在FIFO 缓冲区的字节数
//写入FIFOData寄存器增加,读减少FIFOLength
lastBits = ReadRawRC(RegSecondaryStatus) & 0x07;
if (lastBits)//显示最后接收字节的有效位个数如果为0 整个字节有效
{
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);//读出FIFO的数据
}
}
}
else if (ReadRawRC(RegErrorFlag)&0x01)//如果检测到一个位冲突该位置位该位在PrepareRx
//状态中接收器的启动阶段自动清零
{
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);
}
}
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;
} |