Go Down

Topic: Multiplexing SPI LINES (Read 1 time) previous topic - next topic

Lennyz1988

Mar 09, 2017, 06:11 pm Last Edit: Mar 09, 2017, 06:32 pm by Lennyz1988
Hi,

I got 5 MFRC55 (RFID) reader. When I hook them up together I get a lot of noise on the line. Sometimes it works and sometimes it doesn't.

So it's suggested to use multiplexing on the line. I quote:

Quote
"The solution is to use multiplexers for each arduino pin: SCK, MOSI, MISO, then bring every card's SDA pin to GND so they are all selected. Then you initiate just one class object, and start it for each card in turn. That way you can have as many RFID readers in communication as you want, limited only by the multiplexers. "
So I tried that.

I attached a CD4051 Multiplexer on one line. In this case the SCK line and tried to attach 1 reader. It failt. The Arduino does not see the RFID reader. So I am a bit stuck here.

- I connected the SCK line to port 0 on the CD4051.
- If I replace the RFID line on the multiplexer with a LED, the  LED works fine. So the multiplexer is connected in the way it should be.
- I can get the RFID to work connected directly to the Arduino.

I feel like i'm close to getting it to work, but I am a bit stuck on what to try next.

Code: [Select]
/*
 * --------------------------------------------------------------------------------------------------------------------
 * Example sketch/program showing how to read data from a PICC to serial.
 * --------------------------------------------------------------------------------------------------------------------
 * This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
 *
 * Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
 * Reader on the Arduino SPI interface.
 *
 * When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
 * then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). When
 * you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
 * will show the ID/UID, type and any data blocks it can read. Note: you may see "Timeout in communication" messages
 * when removing the PICC from reading distance too early.
 *
 * If your reader supports it, this sketch/program will read all the PICCs presented (that is: multiple tag reading).
 * So if you stack two or more PICCs on top of each other and present them to the reader, it will first output all
 * details of the first and then the next PICC. Note that this may take some time as all data blocks are dumped, so
 * keep the PICCs at reading distance until complete.
 *
 * @license Released into the public domain.
 *
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 */

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          53         // Configurable, see typical pin layout above

int addressA = 1;
int addressB = 2;
int addressC = 3;

int A = 0;      //Address pin A
int B = 0;      //Address pin B
int C = 0;      //Address pin C



MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
 
  pinMode(addressA, OUTPUT);
  pinMode(addressB, OUTPUT);
  pinMode(addressC, OUTPUT);
  multiplex();
 
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

void loop() {
  multiplex();
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}

// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

void multiplex()
{
    A = bitRead(0,0); //Take first bit from binary value of i channel.
    B = bitRead(0,1); //Take second bit from binary value of i channel.
    C = bitRead(0,2); //Take third bit from value of i channel.

    //Write address to mux
    digitalWrite(addressA, A);
    digitalWrite(addressB, B);
    digitalWrite(addressC, C);

   //digitalWrite(outputpin2, 1);
}

knut_ny

#1
Mar 09, 2017, 10:31 pm Last Edit: Mar 09, 2017, 10:31 pm by knut_ny
dont know if the mux fools you..,
but this:
Quote
t.... and start it for each card in turn.
Ny

Lennyz1988

dont know if the mux fools you..,
but this:
It shouldn't matter when I only connect one reader to the mux right?

knut_ny

Ny

Grumpy_Mike

#4
Mar 11, 2017, 04:22 am Last Edit: Mar 11, 2017, 04:25 am by Grumpy_Mike
Quote
The solution is to use multiplexers for each arduino pin: SCK, MOSI, MISO, then bring every card's SDA pin to GND so they are all selected.
That is crap. All the lines can be common apart from the SDA, that is the one you must put through the multiplexer.

This is a circuit I used on a Raspberry Pi, it will also work for any 3V3 Arduino. If you have a 5V Arduino you must put a potential divider on each output pin from the Arduino to the reader. That is all the pins except Dout. And power the multiplexer with 5V.


Lennyz1988

That is crap. All the lines can be common apart from the SDA, that is the one you must put through the multiplexer.

This is a circuit I used on a Raspberry Pi, it will also work for any 3V3 Arduino. If you have a 5V Arduino you must put a potential divider on each output pin from the Arduino to the reader. That is all the pins except Dout. And power the multiplexer with 5V.


Thank you for your answer. Indeed I can get 3 rfid reader to work reliably with common lines. But when I add the 4th or the 5th rfid reader then sometimes it works and sometimes it doesn't work.

The total cable length is also around 20 meters in total. So that's also a source of the problem. That's why I started looking into multiplexing.

If I cannot work the multiplexing out, then i'm going to use 2 Arduino's and share the output between the ARduino's with a RF24L01+ chip.

Grumpy_Mike

Quote
The total cable length is also around 20 meters in total. So that's also a source of the problem.
It is indeed and it is not a problem multiplexers will solve

Quote
then i'm going to use 2 Arduino's and share the output between the ARduino's with a RF24L01+ chip.
Always a bad idea to use more than one Arduino on a project.

You need buffering on those lines, use a AMLS2631A to send a signal and then use a AMLS2632A on the far end to receive it. They are differential drivers / receivers and communicate each signal over a pair of twisted wires. You get four buffers in a package.

Lennyz1988

#7
Mar 22, 2017, 01:39 pm Last Edit: Mar 22, 2017, 01:51 pm by Lennyz1988
It is indeed and it is not a problem multiplexers will solve
Always a bad idea to use more than one Arduino on a project.

You need buffering on those lines, use a AMLS2631A to send a signal and then use a AMLS2632A on the far end to receive it. They are differential drivers / receivers and communicate each signal over a pair of twisted wires. You get four buffers in a package.
I was on vacation for a few days so it took me a little longer to reply back.

I assume you talk about the 26LS31/26LS32 differential drivers/receivers. Because when I google for the types you mention I don't get any results.

Can I just hook them up like mentioned in the datasheet? Or do I need to write some extra coding?

Datasheet

Could you explain why it would be a bad idea to use 2 Arduino's connected with each other trough serial. I can imagine that it would not be the most efficient way, but it could also be a solution to the problems I am having.

The second Arduino would only have to send a "ok"  when the proper card is scanned. It doesn't need to send a "false" when the wrong card is scanned.

Grumpy_Mike

Sorry dyslexia kicking in I meant AM26LS31A and AM26LS32A.

Quote
Can I just hook them up like mentioned in the datasheet
Yes.

Quote
Or do I need to write some extra coding?
No.

Quote
but it could also be a solution to the problems I am having.
No

Quote
Could you explain why it would be a bad idea to use 2 Arduino's
Because there is simply no need to have two, you can do all you want with one.

Lennyz1988

#9
Mar 22, 2017, 08:00 pm Last Edit: Mar 22, 2017, 08:10 pm by Lennyz1988
Sorry dyslexia kicking in I meant AM26LS31A and AM26LS32A.
Yes.
No.
No
Because there is simply no need to have two, you can do all you want with one.
Thank you for the clarification.

Is the following assumption correct?

* I have 5 readers and 1 Arduino
* MISO, MOSI, CLK need buffering on the lines. SS does not.

- Do I need to place the DS26LS31 or the DS26LS32 near the Arduino? My guess would be the DS26LS32 because that's the receiver.

- If so then does every RFID reader need a DS26LS31? Or do I need to place 1 in the center and make every MISO, MOSI, CLK line common and connect it to only one DS26LS31?

- Or do I need to place 5 DS26LS31 near the RFID and then make the lines common and connect them to one DS26LS32? Am I right in thinking this is the approach?


Datasheet DS26LS31

Datasheet DS26LS32

Grumpy_Mike

#10
Mar 22, 2017, 08:54 pm Last Edit: Mar 22, 2017, 08:56 pm by Grumpy_Mike
Quote
* MISO, MOSI, CLK need buffering on the lines.
Yes
Quote
SS does not.
No.

If they are remote then the MOSI, CLK SS need the transmit buffer at the Arduino end and the receiver buffer at the reader end. The MISO needs buffering with a transmitter at the reader end and a receiver at the Arduino end.

In addition because the Arduino is 5V and the reader is 3v3 then the MOSI, CLK SS need cutting down to 3v3 between the receiver and the reader.

Quote
If so then does every RFID reader need a DS26LS31?
It depends on how far your readers are apart as well as remote from the Arduino.
You have not explained your setup apart from saying
Quote
The total cable length is also around 20 meters in total.

Lennyz1988

#11
Mar 23, 2017, 08:47 am Last Edit: Mar 23, 2017, 09:02 am by Lennyz1988
YesNo.

If they are remote then the MOSI, CLK SS need the transmit buffer at the Arduino end and the receiver buffer at the reader end. The MISO needs buffering with a transmitter at the reader end and a receiver at the Arduino end.

In addition because the Arduino is 5V and the reader is 3v3 then the MOSI, CLK SS need cutting down to 3v3 between the receiver and the reader.
It depends on how far your readers are apart as well as remote from the Arduino.
You have not explained your setup apart from saying
I am trying to build a puzzle for a friend.

- 5 MFRC522 modules are hooked to a wall. The modules are 50cm-1m apart from each other.
- 1 Arduino will be put behind the ceiling.
- To every module there will be a CAT5E cable running with every cable being around 5-7 meters in length. So the total length will be around 25-35 meters in total. I cannot put a wire horizontally from one RFID reader to another. The cable needs to go up to the ceiling first.
- 1 RFID card will be programmed to be connected to 1 Reader. So there will be 5 RFID cards in total.
- If the right card is held before the right reader a LED will light up. So there will be 5 LEDS in total.

That is the setup. If I forgot to tell you other information that you need please let me know.

/edit

Let's say I make some adjustments and make a cable run horizontally between all the RFID readers. That will be a cable about 7 meters in length. Then I connect every RFID to that cable with another 50cm cable. So 5 readers will be around 2,5 meter extra cable.

Then my total cable length will be around 9,5-10 meters. Will that help a lot?


Grumpy_Mike

Tricky, you are on the edge of needing buffers but I wouldn't entirely rule out it working without. I would try it just by itself first.

Lennyz1988

Tricky, you are on the edge of needing buffers but I wouldn't entirely rule out it working without. I would try it just by itself first.
Ok I will try to find out if it possible to shorten the wires.

In the mean while I am also going to order the differential drivers / receivers.

So if I understand it correctly I need to following extra parts:

MOSI + CLK + SS

2x transmitter (placed near the Arduino) >> Room for 8 lines to buffer >> 1x MOSI + 1x CLK + 5x SS
5x receiver (placed near the 5 RFID)

The lines need to become common before going into the transmitter (is this correct?)

MISO

1x receiver (placed near the Arduino)
5x transmitter (placed near the 5 RFID)

The lines need to become common before going into the receiver (is this correct?)

Is this correct?

Grumpy_Mike

I am a bit confused can you draw a schematic or block diagram of what you propose.

Go Up