I have a problem with FM17XX SCR ICS.
There is a circuit with LPC2103F, acting as host and FM1702NL, connected to host via SPI as slave.
According to man FM17XX is compatible with NXP MF RC500, so I use MF RC500 c-language basic function library in my firmware.
Circuit works with MIFARE 1K classic cards. It detects cards, authenticates in specific sectors and reads data fine, however it writes information on a card always with the same error MI_BITCOUNTERR (-11).
What could be a possible solution to this problem?
Code of writing function:
//NXP(c) signed char Mf500PiccCommonWrite( unsigned char cmd, unsigned char addr, unsigned char datalen, unsigned char *data) //(46) { unsigned char bitsExpected; signed char status = MI_OK;
// ************* Cmd Sequence ********************************** PcdSetTmo(1000); // long timeout
WriteRC(RegChannelRedundancy,0x07); // TxCRC, Parity enable
ResetInfo(MInfo); MSndBuffer[0] = cmd; // Write command code MSndBuffer[1] = addr; MInfo.nBytesToSend = 2;
status = PcdSingleResponseCmd(PCD_TRANSCEIVE, MSndBuffer, MRcvBuffer, &MInfo);
if (status != MI_NOTAGERR) // no timeout error { if (MInfo.nBitsReceived == 8 && (ReadRC(RegDecoderControl) & 0x01)) { // upper nibble should be equal to lower nibble, otherwise // there is a coding error on card side. if ((MRcvBuffer[0] & 0x0f) == ((MRcvBuffer[0] >> 4) & 0x0f)) bitsExpected = 8;
else { bitsExpected = 0; } }
else //bitsExpected = 4; bitsExpected = 8; //HACK!!
if (MInfo.nBitsReceived != bitsExpected) // ACK / NACK expected { if (bitsExpected == 0) status = MI_CODINGERR; else status = MI_BITCOUNTERR; }
else // 4 bit received { MRcvBuffer[0] &= 0x0f; // mask out upper nibble
switch(MRcvBuffer[0]) { case 0x00: status = MI_NOTAUTHERR; break; case 0x0a: status = MI_OK; break; default: status = MI_CODEERR; break; } } }
if ( status == MI_OK) { ResetInfo(MInfo); memcpy(MSndBuffer,data,datalen); MInfo.nBytesToSend = datalen;
if (status != MI_NOTAGERR) // no timeout occured { if (MInfo.nBitsReceived == 8 && (ReadRC(RegDecoderControl) & 0x01)) { // upper nibble should be equal to lower nibble, otherwise // there is a coding error on card side. if ((MRcvBuffer[0] & 0x0f) == ((MRcvBuffer[0] >> 4) & 0x0f)) bitsExpected = 8;
else //bitsExpected = 4; bitsExpected= 8; //HACK!! if (MInfo.nBitsReceived != bitsExpected) // ACK / NACK expected { if (bitsExpected == 0) status = MI_CODINGERR;
else status = MI_BITCOUNTERR; }
else // 4 bit received { MRcvBuffer[0] &= 0x0f; // mask out upper nibble switch(MRcvBuffer[0]) { case 0x00: status = MI_WRITEERR; break; case 0x0a: status = MI_OK; break; default: status = MI_CODEERR; break; } } } } return status; }