TCA9548A I2C multiplexer unable to work with I2C PN532 NFC reader

I have an adafruit TCA9548A I2C multiplexer and a PN532 NFC reader. I can't get them to work.

I'm running off an Arduino Uno, I hooked up the multiplexer with the guide and tested it out with a I2C 16x2 LCD and I'm able to call to it and write stuff to it. Code below.

//------TCA9548A I2C multiplexer----------------------
#include <Wire.h>
#define TCAADDR 0x70

void tcaselect(uint8_t i) 
{
  if (i > 7) return;
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();  
}
//--------------LCD-----------------------------------------------
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27 ,16,2);  // set the LCD address to 0x3F for a 16 chars and 2 line display
//-------------------------------------------------------------
int output_pin=10;

void setup(void) 
{
  pinMode(output_pin,OUTPUT);

  Serial.begin(9600);
  Serial.println("TCA9548A Test");
  
  /* Initialise the 1st sensor */
  tcaselect(7);
  lcd.init();
  lcd.clear();         
  lcd.backlight();      // Make sure backlight is on

}


void loop(void) 
{ 
  // Print a message on both lines of the LCD.
  lcd.setCursor(0,0);   //Set cursor to character 0 on line 0
  lcd.print("Hello my world!");
  
  lcd.setCursor(0,1);   //Move cursor to character 0 on line 1
  lcd.print("LCD Tutorial");
}

I used the I2C scanner sketch they used in the guide to see if the device is recognized and the PN532 is there, but when I try to run a sketch with the multiplex code with the PN532 the code stalls at the first serial print and only prints out "I2I2I2" on the serial monitor. I tried asking Adafruit tech support and they said that it was

"The Wire library is prone to hanging when there is a problem on the i2c bus. Since it only hangs when the PN532 is active, the PN532 is the primary suspect. I explained in my earlier post how the PN532 can be a major source of electromagnetic interference."

I added twisted pairs of cables to the connections to the PN532 and the problem persists. I can get the PN532 working independently so i know my connections and PN532 sketch works. I'm not sure how to diagnose stuff that happens in the background of Arduino. Thank you for any help in advance.

//------TCA9548A I2C multiplexer----------------------
#include <Wire.h>
#define TCAADDR 0x70

void tcaselect(uint8_t i) 
{
  if (i > 7) return;
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();  
}
//--------------PN532-----------------------------------------------
#include <DFRobot_PN532.h>
#define  BLOCK_SIZE      16
#define  PN532_IRQ      (2)
#define  INTERRUPT      (1)
#define  POLLING        (0)

DFRobot_PN532_IIC  nfc1(PN532_IRQ, POLLING); 
DFRobot_PN532:: sCard_t NFC1card;

//-------------------------------------------------------------
int output_pin=10;

void setup() 
{
  pinMode(output_pin,OUTPUT);

  Serial.begin(115200);
  Serial.println("I2C mult Test");
  
  /* Initialise the 1st I2c Device */
  tcaselect(1);
  if(!nfc1.begin())
  {
    /* There was a problem starting the PN532 ... check your connections */
    Serial.println("NFC 1 not connected");
    while(1);
  }
  Serial.println("Please place the NFC card/tag on module..... ");
}


void loop() 
{ 

  tcaselect(1);
/* Call I2C 1 *///-------------------------
  if (nfc1.scan()) 
  {
    //Read the basic information of the card
    NFC1card = nfc1.getInformation();
    Serial.println("----------------NFC1 card/tag information-------------------");
    Serial.print("UID Lenght: "); Serial.println(NFC1card.uidlenght);
    Serial.print("UID: ");
    for (int i = 0; i < NFC1card.uidlenght; i++) {
      Serial.print(NFC1card.uid[i], HEX);
      Serial.print(" ");
        //call here 
            if (readRFID1()) {
          // Access granted.
            digitalWrite(output_pin, LOW);
            digitalWrite(LED_BUILTIN, LOW);
            Serial.println("Valid");
           }
          else {
        // Access denied
            digitalWrite(output_pin, HIGH);
            digitalWrite(LED_BUILTIN, HIGH);
            Serial.println("Invalid");
           }
    }
    Serial.println("");
  }
  else 
  {
    //Serial.println("no card!");
    digitalWrite(output_pin, HIGH);
    digitalWrite(LED_BUILTIN, HIGH);
  }
//----------------------------------------
  delay(500);
}

boolean readRFID1()
{
  byte card_ID[4];                                        // card UID size 4byte
  const int numOfCards = 1;                               // the number of cards used. this can change as you want
  byte cards[numOfCards][7] = {{0x93, 0xDB, 0x1B, 0xFB}}; // array of UIDs of rfid cards
  //1 0xFD, 0xF8, 0x92, 0xDA 
  //2 0x3D, 0xD2, 0x93, 0xDA 
  //3 0xCD, 0xE7, 0x94, 0xDA 
  //4 0x0D, 0x74, 0x94, 0xDA
  //5 0xCD, 0x73, 0x94, 0xDA
  //6 0x7D, 0xD2, 0x93, 0xDA
  for (byte i = 0; i < NFC1card.uidlenght; i++)
  {    card_ID[i] = NFC1card.uid[i];  }

  for (int i = 0; i < numOfCards; i++)
  {
    if ((card_ID[0] == cards[i][0]) && (card_ID[1] == cards[i][1]) && (card_ID[2] == cards[i][2]) && (card_ID[3] == cards[i][3]))
    {    return true;    }
  }

 return false;
}

  • please provide a schematic of your wiring for your sketch with PN532.
  • What is the cable lenght from the arduino to the TCA9548A?
  • What is the cable length from the TCA9548A to the PN532?

Real pictures of your installation can help to identify potential issues.

I can't quite figure out, from your description, what you have tested.

You tested an LCD display, through the multiplexer, and that worked ok?

You connected the RFID sensor, connected through the multiplexer, and ran i2c scanner and the sensor was detected?

Have you tested the RFID sensor connected direct to the Uno, without the multiplexer? Did that work?

Also can I ask why you are using a multiplexer at all?

Yes, I tested a I2C 16x2 LCD through the multiplexer and it worked.

Yes, the scanner showed the RFID sensor.

Yes, I connected the RFID directly to the Uno and it works, both wiring and sketch.

I plan to connect multiple PN532 RFID sensors to this multiplexer. I wanted to test with one before adding more.

Ok, good answers.

Does the RFID module have built-in pull-up resistors on the SDA & SCL pins? If not, you need to add external pull-up resistors. (They were not needed when you connected the RFID module directly to the Uno because the Uno has pull-up resistors built-in to the atmega chip which are enabled when your code executes Wire.begin() ).

The above is only a guess. The fact that the i2c scanner found the RFID module means it probably does have pull-up resistors.

Might be worth trying some external pull-up resistors anyway, such as 4K7.

Your diagram shows the Uno's 5V & ground pins being shorted out, which would damage the Uno. It also shows wires in the same holes as the pins of the multiplexer module, which would damage the breadboard. Hopefully you haven't done either of those things in reality, your photo doesn't look like you did. But no point posting an inaccurate diagram if you want the forum to check it for you.

You were asked to provide a schematic by @noiasca. What you posted is not a schematic. Are you using Fritzing? If so, switch to schematic view and all your components and their connections will be copied from the breadboard view (including mistakes). You can then re-oragsnise the components and re-draw the wires to make a real schematic.

I'm not sure if it does. This is the module i'm using. I added a 10k resistor connecting the SD1 and SC1 to 5V. The scanner sketch serial monitor only prints out "TCAScanner ready!" and then nothing else. If i pull them out and reset the arduino they come up in ther serial monitor as port 1.

Here is the schematic view from fritz. I didn't have the multiplexer part so i used headers as the pins. They are labeled as top left and bottom left of the multiplexer. In my before image I has pumped GND and 5V this is was a drawing error my circuit GND and 5V are connected correctly.

Thanks for trying, but it's not very helpful yet. You need to find the multiplexer and RFID parts and install them into Fritzing, or, and this may be easier, hand-draw your schematic.


The schematic is better, and I can't see any serious error. You schematics will be as good as your wiring diagrams with a little more practice.

You need 2 resistors. Is that what you meant?

I added two resistors one for each SD1 and SC1 connecting them to 5V

Good.

I do not know what to suggest you check next.

Hi, I'm trying to do the same thing (multyplexing many pn532), has the problem been solved?

1 Like

same thing here (I want multyplexing many pn532). any advice.

You need to add Wire.begin() in your setup code, before you call tcaselect(#).

No pull-up resistors were required.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.