Handling two different UART device with one port

Discussion in 'Embedded Systems and Microcontrollers' started by majidkhalili, Oct 3, 2013.

  1. majidkhalili

    Thread Starter New Member

    Oct 3, 2013
    9
    0
    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
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,364
    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.
     
  3. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    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.
     
  4. majidkhalili

    Thread Starter New Member

    Oct 3, 2013
    9
    0
    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
     
  5. majidkhalili

    Thread Starter New Member

    Oct 3, 2013
    9
    0
    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
     
  6. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    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...
     
  7. majidkhalili

    Thread Starter New Member

    Oct 3, 2013
    9
    0
    yes , this is exactly the problem
    so, its just like a buffer that get the received data,now i do that just by some function i write in my program
    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 ?
    its the matter of money ;)
     
  8. majidkhalili

    Thread Starter New Member

    Oct 3, 2013
    9
    0
    and about atmega 168 , it just has one USART , how do u say it has 3 ?
     
  9. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    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?
     
  10. Xkyve

    Member

    Nov 30, 2012
    32
    2
  11. majidkhalili

    Thread Starter New Member

    Oct 3, 2013
    9
    0
    i think the best solution is to use 1280 , and "Best" means easiest not the cheapest :(
     
  12. majidkhalili

    Thread Starter New Member

    Oct 3, 2013
    9
    0
    yeah
    i think 1280 might be the easiest way
    because i have to use the data received interrupt function
     
Loading...