ATrappmann / PN5180-Library

PN5180 library for Arduino
GNU Lesser General Public License v2.1
104 stars 92 forks source link

STM32 PN5180, using ISO14443 card reader #46

Closed tsotnek closed 2 years ago

tsotnek commented 2 years ago

Hello,

I am working on a project with PN5180, my end goal is to emulate a Type A card. But for now, I just want to use PN5180 as PCD and read 14443 cards.

I have followed your code which is written very well and modified it slightly for the STM32, I am using HAL drivers.

ATM, I followed 14443 code and I am currently stuck on send_data command. I rewrote this arduino for loop

void loop() {
  if (errorFlag) {
    uint32_t irqStatus = nfc.getIRQStatus();
    showIRQStatus(irqStatus);

    if (0 == (RX_SOF_DET_IRQ_STAT & irqStatus)) { // no card detected
      Serial.println(F("*** No card detected!"));
    }

    nfc.reset();
    nfc.setupRF();

    errorFlag = false;
    delay(10);
  }
  Serial.println(F("----------------------------------"));
  Serial.print(F("Loop #"));
  Serial.println(loopCnt++);
  if (!nfc.isCardPresent()) {
    Serial.print(F("no card found"));
    return;
  }
  uint8_t uid[8];
  if (!nfc.readCardSerial(uid)) {
    Serial.print(F("Error in readCardSerial: "));
    errorFlag = true;
    return;
  }
  Serial.print(F("card serial successful, UID="));
  for (int i=0; i<8; i++) {
    Serial.print(uid[i], HEX); 
    if (i < 2) Serial.print(":");
  }
  Serial.println();

  Serial.println(F("----------------------------------"));

  delay(1000);  
}

in stm32 as...

while(1){

  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
      if (errorFlag) {
        resetPN5180();
        SetupRF();

        errorFlag = false;
        HAL_Delay(10);
      }

      if(!isCardPresent()){
          break;
      }

      HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);

      uint8_t uid[8];
      if(!readCardSerial(uid)) {
        errorFlag = true;
        break;
      }

      HAL_Delay(1000);

  }

  /* USER CODE END 3 */
}

So whenever readCardSerial(uid) function is executed, it calls activateTypeA function, which calls sendData, so I followed all of the code which was written by you guys.

When in sendData my program freezes. after going to IDLE first and then in Transceive state, when you are waiting for WaitTransmit, my application returns WAIT_FOR_DATA all the time. I even tried to manually change the initiator bit in TRANSCEIVE_CONTROL register by setting the 0th bit to 1, but it still returns WAIT_FOR_DATA. Could you maybe assist me with this problem?

Thank you in advance!

tsotnek commented 2 years ago

Ok, I fixed it, silly me. So as it is said in the datasheet when you enter the transceive state, PN looks at the initiator bit in TRANSCEIVE_CONTROL register and I manually set this bit to one in the send_data function and it fixed the problem. https://imgur.com/a/aB2TzLK