This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

2 UARTs

Hi guys,
Here is the situation I've 89c51 microcontroller board which I want to connect with PC as well as GSM but as everybody knows it(8051) has only one UART so one solution is try using 87xx or 83xx series of controller but that means I'll have to change my programmer. So what I'm thinking is I'll use simple mux/demux for Tx/Rx of 8051. I want to know will it be o.k.? Can simple AND or OR gates can handle data rate of 9600bps?

Thank you very much in advance.

Parents Reply Children
  • We have a similar situation and have implemented an analog switch to switch between the two ports rather cheap way to solve it but with a small possibility of missing data if not coded right :)

  • ya after MAX232 i.e. when signals are TTL level I guess my switching occurs properly but serial initialization routine can't be activated properly have a look

     #define R 1
     #define G 0
       .
       .
       .
      Long_Delay(200);
      Select_Serial = R;
      LongDelay();
      Init_Serial();
      Xmit_Static_Char('R');
      P0 = 0x01;
      LongDelay();
      Select_Serial = G;
      LongDelay();
      Init_Serial();
      Xmit_Static_Char('G');
      P0 = 0x02;
      LongDelay();
      Select_Serial = R;
      Init_Serial();
      Xmit_Static_Char('R');
      P0 = 0x01;
      LongDelay();
      Select_Serial = G;
      LongDelay();
      Init_Serial();
      Xmit_Static_Char('G');
      P0 = 0x02;
    

    Here I can see R(1st terminal) G(2nd terminal) and R(1st) but that also sometimes then nothing but P0 shows LED status correctly as 0x01,0x02,0x01,0x02 etc.

  • That would be good option but my problem is I want switching to be handled by uC according to command comes to it Anyway Thanks for sharing your opinion

  • It's fairly pointless posting code with all the important bits missing!

    What does Select_Serial do?
    What does Init_Serial() do?
    What does Xmit_Static_Char() do?

    Where is serial reception handled?

  • Select_Serial is pin 3.2 to select which serial line to select (uC to terminal1 or uC to terminal2)
    Serial_Init initialize serial port i.e. TMOD 20h,SCON 50h etc.
    Xmit_Static_Char transmit a character.
    and reception is handled on hyperterminal on pc

  • "Select_Serial is pin 3.2 to select which serial line to select (uC to terminal1 or uC to terminal2)"

    Does it work?
    Have you tested that the hardware does actually correctly route the signals?

    "Serial_Init initialize serial port i.e. TMOD 20h,SCON 50h etc."

    Again, does it work?
    Have you tested that the hardware is actually correctly configured to the correct baud rate, etc?

    "Xmit_Static_Char transmit a character."

    Yet Again, does it work?
    Have you tested that that it actually transmits the correct character?

    "reception is handled on hyperterminal on pc"

    Now I'm confused!
    In which direction is this multiplexing occurring?!

  • Why do you repeat this for every single transmitted character?!

  • Yes Andy the configuration i.e. H/W and S/W are working just fine. I am using these settings for other programs. Even switching is working perfectly as I can see status on port 0 with LEDs and For that initialization every time : At first I didn't use it but as that program didn't work I thought because of delay serial initialization may get hampered so I'm doing it every time anyway that way it won't cause any harm except little more machine cycles.

  • I guess I'm doing some stupid mistake I'll have to rectify it

  • Can anybody let me know what should following programing do? Is main in keil is reentrant? even with for loop following pogram work infinitely

    //program to transmit a chaaracter
    #include<reg51.h>
    
    sbit Select = P3^2;
    void Delay(void);
    
    
    void main(void)
     {
      int i;
      SCON = 0x50;
      TMOD = 0x20;
      TH1  = 0xFD;
      TR1  = 1;
      for(i=0; i<21; i++)
       {
        Select = 0;
            SBUF = 'p';
            while(TI == 0){}
            TI = 0;
            P2 = 'p';
            Delay();
            Delay();
            Delay();
            Delay();
            Delay();
            Select = 1;
            SBUF = 'q';
            while(TI == 0){}
            TI = 0;
            P2 = 'q';
            Delay();
            Delay();
            Delay();
            Delay();
            Delay();
       }
    
     }
    
    
     void Delay(void)
      {
       unsigned char i;
       for(i=0;i<=200;i++)
        {}
       return;
      }
    
    
    
    

  • Is main in keil is reentrant
    This has nothing to do with Keil.
    main is 'reentrant' in the sense that it is entered after each reset, but in no other respect.

    if you do not have an unbreakable loop in in your program will just 'overflow' at the end of main().

    This is EMBEDDED and in EMBEDDED you do not exit from (the root) main(). ONLY if you have code with a main() that call code with a main() (a very construed construct) could you have a returning main().

    Erik

  • Then why would above program work infinitely instead of only 21 times it transmits p and q infinitely

  • That depends on the startup code.

    If the startup code immediately returns to main() or performs a watchdog-reset or a "pseudo-reset", your program will continue to send data.

    If you want your program to perform 21 interations and then stop, you should add an infinite loop at the end of the program. For processors who support it, the infinite loop could contain a sleep instruction, to conserve power.

  • Thank you very much Per Westermark. That worked well when I put while(1){} anyway what is this start up code - keil used to ask every time do you want to copy and stuff but I don't understand it much. Can you please guide me where can I read about it or so I would like to gain more knowledge

  • The erased state of EPROM is FF - which is the opcode for MOV R7,A

    So your could could run off the end of main(), then execute all the erased EPROM locations as MOV R7,A until the address spaces wraps around and it returns to the reset vector at C:0x0000

    The delay due to executing these MOV R7,A instructions is likely to be imperceptible, giving the impression that main() is just executing continuously...