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);
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.
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?)
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.