Random analog readings when using SPI communication with NFC

punitguptatkd
Posts: 1
Joined: Thu Sep 26, 2019 2:04 am

Random analog readings when using SPI communication with NFC

Postby punitguptatkd » Thu Sep 26, 2019 2:26 am

We're using NXP's MFRC630 NFC Front-end chip with iWander's library for Arduino Ide. When just doing the Analog Reading Example, it's quite fine but as soon as we do NFC reading as well, it starts outputting some random numbers. Is there some fault with the library or any hardware issues with ESP32?

Here's my code:

Code: Select all

#include <Arduino.h>
#include <SPI.h>
#include <mfrc630.h>
#include <WiFi.h>
const char* ssid = "XXXXXXXXXXX";
const char* password = "XXXXXXXXXXXX";
#include <WiFiMulti.h>
WiFiMulti WiFiMulti;
#define CHIP_SELECT 5


void mfrc630_SPI_transfer(const uint8_t* tx, uint8_t* rx, uint16_t len) {
  for (uint16_t i=0; i < len; i++){
    rx[i] = SPI.transfer(tx[i]);
  }
}

void mfrc630_SPI_select() {
  SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));  // gain control of SPI bus
  digitalWrite(CHIP_SELECT, LOW);
}

void mfrc630_SPI_unselect() {
  digitalWrite(CHIP_SELECT, HIGH);
  SPI.endTransaction();    // release the SPI bus
}


void setup() {

  WiFiMulti.addAP(ssid,password);

  while(WiFiMulti.run() != WL_CONNECTED) {
    }


  // Set the chip select pin to output.
  pinMode(CHIP_SELECT, OUTPUT);

  // Start the SPI bus.
  SPI.begin();


  // Set the registers of the MFRC630 into the default.
  mfrc630_AN1102_recommended_registers(MFRC630_PROTO_ISO14443A_106_MILLER_MANCHESTER);

  // This are register required for my development platform, you probably have to change (or uncomment) them.
  mfrc630_write_reg(0x28, 0x8E);
  mfrc630_write_reg(0x29, 0x15);
  mfrc630_write_reg(0x2A, 0x11);
  mfrc630_write_reg(0x2B, 0x06);
}

void loop() {

  const uint16_t port = XXXX;
    const char * host = "XXXXXXXXXX";

WiFiClient client;
    if (!client.connect(host, port)) {
    }

 client.println("BC006\r");
 
 while (client.connected()){
  delay(1);

 int sensorValue = analogRead(33);
 
  hit1 = sensorValue / 3;

 if (hit1 >= 75) {
      uint16_t atqa = mfrc630_iso14443a_REQA();
  if (atqa != 0) {

client.println(hit1);

 
    }

     }
 }
}



Who is online

Users browsing this forum: No registered users and 151 guests