I tried to code to make bidirectional send and receive communication on Arduino Uno. but Arduino Uno has one TX and RX pin. now I changed to the Arduino mega board. how can I send data and receive data at the same time using Arduino mega board using UART / interrupts?
You use Serial1..4 just like Serial. Write or print as required and check for received chars using available(). No interrupts are required.
DrDiettrich is correct. The async serial has both a TX and Rx pins as you noted. You connect Tx on one unit to Rx on the other. These are separate signal paths each going in a different direction. There is no relationship between them or the data that is being sent. They can even be different bauds if you want. For the Uno the best solution is to use a external USART. Software serial is nice but does not do concurrent send and receive. You can use the serial port on the UNO at the expense of the console if you want. Going into debug and programing modes will be convoluted as it is the same two pins. This should get you started.
The SCC2691 by Philips has the ability for full duplex operation with different bauds for send and receive. They are selected by using bits in the CSR register.
Not really, the RX and TX pins of one UART interface use the same baudrate, you cannot define a baudrate for sending and one for receiving. I agree with the rest.
How I did it...
how can I code it? can you give me the code?
Can you give me the code?
I believe the best solution for you is to recommend you get the Arduino Cookbook, either purchase it or check it out of the library. You will find the code you need in there along with explanations which will help you understand what you are doing.
Can you help me? What situation have you encountered where your data must be received and sent at the same time? In 50 years of data communication, I have never encountered such a situation.
Paul
Meditating on this over night, I recall there were some local area networks that did this. I wonder if the OP is attempting to re-invent a LAN?
if (Serial2.available()) Serial1.write(Serial2.read());
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.