Yes,
you can do serial.begin any where you like at any time. The code sets up control registers for the hardware serial. It is not something that you can only call once. Many of my projects have menus and lcd and keypads so I can select baud rate on the fly.
"can i connect both to the same serial port (RX0)? "
How would you keep one from messing up the tranmissions of the other?
If you could guarantee that only 1 at a time was sending, then you could add a buffer that would let either one control the line.
If not, go with seperate serial receive ports.
CrossRoads:
"can i connect both to the same serial port (RX0)? "
How would you keep one from messing up the tranmissions of the other?
hmmm i'm controlling a door. so whichever RFID module gets triggered i would want the door to open. how will each others transmission affect each other?
CrossRoads:
So the RFIDs are under your control as to they transmit?
Or do they send out asynchounously?
they're sent out asynchronously
KE7GKP:
The serial port can only be 1/HIGH/"mark" or 0/LOW/"space" at any moment. How would you get the pin to be "HIGH" if the other RFID is pulling it "LOW" (or vice-versa)? You can't do a "logical OR" on serial data.
I see where you're getting... but i don't have enough serial ports on the mega to give each its own serial port..
I'd like to know what OP is connecting to the Mega that is using up all the serial ports, before making a recommendation to use software serial ports.
Using 2 RFID readers to unlock a single door strikes me as overkill. The reader belongs on the side of the door opposite the locking mechanism.
Now, if the RFID reader was being used to unlatch a door, and the RFID tag user can only be on one side of the door at a time, then there would be no problem connecting both of them to the same serial port.
Ok, since they are asynchronous, they will both be high until one of them starts transmitting.
What you can do is feed both into an AND gate - the output will then follow which ever input goes low.
It can be an actual AND gate, like a 74xx08 (quad 2-input AND gate) or it can be as simple as 2 Diodes - connect the 2 anodes and a pullup resistor to the Rx input, so it sits high, and connect each cathode to the two RFID lines coming in. A line goes low, it pulls the cathode low, pulling the anode low.
Do a test with whatever diodes you have sitting around, see if you get data coming in reliably.
Maybe you need high security and both sides of the door is locked?
In the US, that would be a building code violation.
Maybe two doors, one is enter only the other exit only. Both can be force open with alarm on them but for regular access you swipe in and out like CrossRoads said?!
Well, you could use a small chip (eg. Atmega168 or smaller) per RFID reader. Each one could "listen" on the serial port, and dump what it received onto the I2C bus. Then the main chip could monitor that. That would cost a few dollars per reader, and could be expanded to dozens of them.