ID20LA

Hello, I have connected 3 rfid readers to arduino Mega board.

However i have encountered weird issue. While trying to read tag from serial1,2,3 arduino often crash while doing it. what should I do?

code i’m using is straight taken from bildr page http://bildr.org/2011/02/rfid-arduino/

about electrical wiring- everything is daisy chained except RX wire (as a must).

When I was trying to separate reset pins for each board, this issue also happen.

Define “crash”

OK, after some hours of debuging I’m able to do it honestly.

When I’m pluging signle id20la to serial1 there is no problem, card may lay on the reader, and everything is working ocrrectly. however when I add second reader, connected to serial2 leaving both cards laying of reader causes reseting of board, or slowing down- that so operation that normaly takes second lasts for somethibng round one minute.

even if I try function that separate readings from readers, this issue remain.

void readRFID(int reader) {
	char tagString[13];
	int index = 0;
	boolean reading = false;
	boolean redead = false;

	switch (reader) {

	case 0:
		while (Serial1.available()) {
			redead = true;
			int readByte = Serial1.read(); //read next available byte

			if (readByte == 2) reading = true; //begining of tag
			if (readByte == 3) reading = false; //end of tag

			if (reading && readByte != 2 && readByte != 10 && readByte != 13) {
				//store the tag
				tagString[index] = readByte;
				index++;
			}
		}
		break;
	case 1:
		while (Serial2.available()) {
			redead = true;
			int readByte = Serial2.read(); //read next available byte

			if (readByte == 2) reading = true; //begining of tag
			if (readByte == 3) reading = false; //end of tag

			if (reading && readByte != 2 && readByte != 10 && readByte != 13) {
				//store the tag
				tagString[index] = readByte;
				index++;
			}
		}
		break;
	case 2:
		while (Serial3.available()) {
			redead = true;
			int readByte = Serial3.read(); //read next available byte

			if (readByte == 2) reading = true; //begining of tag
			if (readByte == 3) reading = false; //end of tag

			if (reading && readByte != 2 && readByte != 10 && readByte != 13) {
				//store the tag
				tagString[index] = readByte;
				index++;
			}
		}
		break;
	}

	checkTag(tagString, reader); //Check if it is a match
	clearTag(tagString); //Clear the char of all value

	if (redead) {
		setColor(3 - reader, 4);
	}
	else
	{
		setColor(3 - reader, 0);
	}
	redead = false;

}


void serialEvent1() {
	readRFID(0);
}

void serialEvent2() {
	readRFID(1);
}

void serialEvent3() {
	readRFID(2);

Can’t process more than one thing at a time…

A byte comes in here, gets worked on, a byte comes in over there while the 1st byte is getting worked on, that 2nd byte gets missed…or does it? Then maybe the 2nd byte of the first card comes in but gets missed because the processor is busy pulling the 2nd byte of the 2nd card…and the convoluted list goes on and on.

Think about it for awhile.

Are you using the multiplexor like is described in the bildr page you reference?

It’s probably a good idea :

http://bildr.org/2011/02/cd74hc4067-arduino/

I see you have SerialEventx defined - I don’t know if these are interrupts or what, but…

If they are, then you should block the other interrupts during interrupt handling until you’re finished servicing the one you’re on.

It’s typical to have an event fire (got characters in buffer) and get the characters in the buffer and append them to the appropriate string, examine the string and if it contains the Carriage Return (13) and / or LineFeed (10) then extract just the string (leaving the rest for future processing) and react accordingly.

maybe the multiplexer has a buffer.

maybe you don’t?

also, you have only the one index which gets zeroed each time you enter the readRFID() function so you may be appending characters always starting at the beginning of the string.

(boolean redead : that’s a funny variable name - what’s that about?)

Ok, today I’ve received 16 ch multiplexer. I will check on it, if everything is working.

Hm, I have little problem with reading RX through this multiplexer. Any1 know how to do it?

You’ve completely missed the point.

You can multiplex everything you want all day.

But you can only do one thing at a time.

If the MCU/program/processor/process misses an important part of the decoding, it will fail that whole thing.

6 people saying their ABC’s around you, all start at different times.

You turn to listen to person A begin. Then you hear person B start up so you turn to listen to person B. But since you’ve turned to listen to person B, now you’ve missed some of what person A is saying. And so on and so on…

As far as you’re concerned, not one of them has correctly said their ABC’s. Each one of them has only said pieces/parts of their ABC’s. Why? Because you can only listen to one person at a time.

Substitute MCU for people…

Substitute packets from the RFID for ABC’s.

check this article:

http://bildr.org/2011/02/cd74hc4067-arduino/