Handling two different UART device with one port

Thread Starter

majidkhalili

Joined Oct 3, 2013
9
Hi guys
i dont know if this is the best place ask this , so if i have to post it in different section pls let me know
i have an avr micro controller that is working with PC using one of its serial port , and the avr has only one other serisal port , and i need to work with tow different device using UART , i have know idea what can i do
one of the devices i'm just reading from , and another one i'm bot reading and writing
and the important thing is that for both these devices i have to use the interrupt , so i cant not use just simple mux to handle these to , because they should interrupt the avr to read the value of them , so with mux i migh lose the data

pls tell me any thing that can help
thanks
 

MrChips

Joined Oct 2, 2009
30,802
You can use the internal UART for handling the full duplex device.
Then use the external IRQ to receive the second device.

Or use a microcontroller with two UARTs.
 

sirch2

Joined Jan 21, 2013
1,037
As Mr Chips suggests, Megas have mulitple UARTS, what sort of Arduino are you using? You also get 2 interrupts and the UART has a 64 byte buffer so depending on baud rate you may be able to read the buffer before it over flows.
 

Thread Starter

majidkhalili

Joined Oct 3, 2013
9
You can use the internal UART for handling the full duplex device.
Then use the external IRQ to receive the second device.

Or use a microcontroller with two UARTs.
i dont know exactly what is internal uart ( what does internal means here ?!!!!!! )
about IRQ , how do u mean it should interrupt ? i mean how should i handle the interrupt , a first i just think i can use interrupt to switch between two serial devices using MUX , but i think it may cause data lost
 

Thread Starter

majidkhalili

Joined Oct 3, 2013
9
As Mr Chips suggests, Megas have mulitple UARTS, what sort of Arduino are you using? You also get 2 interrupts and the UART has a 64 byte buffer so depending on baud rate you may be able to read the buffer before it over flows.
i'm using mega128 , as i said one of them is used to handle the communication between pc and micro and there is another one more that i have to handle these two device
 

sirch2

Joined Jan 21, 2013
1,037
OK, so if I understand correctly then the mega128 has 2 USARTs and you are using one to communicate with a PC and you want to connect two other serial devices to the 128.

An internal UART is a small buffer that will hold the serial data until your program gets around to reading it so as long as you program checks the serial frequently enough you may get away with out using an interrupt.

I think what Mr Chips was suggesting is that you use the UART for the read/write device and then for the device you are just reading you connect it to one of the interrupt pins and have it interrupt as soon as data arrives and then just read serial data as it comes in on that pin. Your will need to check you timings because you don't want the UART to overflow while you are bit-banging from the other device.

Or get a mega168 that has 3 UARTs...
 

Thread Starter

majidkhalili

Joined Oct 3, 2013
9
OK, so if I understand correctly then the mega128 has 2 USARTs and you are using one to communicate with a PC and you want to connect two other serial devices to the 128.
yes , this is exactly the problem
An internal UART is a small buffer that will hold the serial data until your program gets around to reading it so as long as you program checks the serial frequently enough you may get away with out using an interrupt.
so, its just like a buffer that get the received data,now i do that just by some function i write in my program
I think what Mr Chips was suggesting is that you use the UART for the read/write device and then for the device you are just reading you connect it to one of the interrupt pins and have it interrupt as soon as data arrives and then just read serial data as it comes in on that pin. Your will need to check you timings because you don't want the UART to overflow while you are bit-banging from the other device.
ok , how should i use interrupt , i mean can how can i do that and detect which device is now interrupting , or the circuit that i have in my mind for the solution u recommend ( using interrupt ) may cause data lost , could u pls tell more about your idea ?
Or get a mega168 that has 3 UARTs...
its the matter of money ;)
 

sirch2

Joined Jan 21, 2013
1,037
My mistake, should have said ATMega 1280, even then I was wrong it has 4!.

I don't know enough about your application to make much further comment. Are you continuously reading from the two devices or are they read/written intermittently? Is there any handshaking prior to data being sent? What are the devices you are communicating with?
 
Top