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

How to set Uart2 ?

Please tell me how to use Uart2 to exchange data?

I Use C51 development and ST uPSD3234A chip.

Parents
  • Jonas,
    I just have a few questions regarding your previously posted code sample:
    1. Where is this "putchar()" function?
    2. Where do you enable your serial interrupt(i.e., perhaps ES2=1 alike statement)?
    3. Why do you need to enable TI2 in initialization? You should only enable TI2 when you have your serial transmit buffer ready. If you do the serial transmit from a function rather than from an interrupt, you can just simply write the first byte to the serial buffer and wait for TI2 to be set. More importantly, you need to clear TI2 before you can write your second byte into SBUF2. I suspect this could be your problem - you enable TI2 but never clear it, therefore no further UART transmit interrupt can occur.

    Good Luck!

Reply
  • Jonas,
    I just have a few questions regarding your previously posted code sample:
    1. Where is this "putchar()" function?
    2. Where do you enable your serial interrupt(i.e., perhaps ES2=1 alike statement)?
    3. Why do you need to enable TI2 in initialization? You should only enable TI2 when you have your serial transmit buffer ready. If you do the serial transmit from a function rather than from an interrupt, you can just simply write the first byte to the serial buffer and wait for TI2 to be set. More importantly, you need to clear TI2 before you can write your second byte into SBUF2. I suspect this could be your problem - you enable TI2 but never clear it, therefore no further UART transmit interrupt can occur.

    Good Luck!

Children
  • Alan,

    Thank you first.

    putchar()is a function that put the char to a Uart supported by the development.

    void initialize_system (void)
    { PCON &= 0x7F;
    SCON = 0x50;
    TMOD |= 0x20;
    TCON = 0x40;
    TH1 = 0xFD;
    TR1 = 1;
    TI = 1;
    }
    The above are codes which already set Uart0 to work successfully.
    I just to change codes to set Uart1 to work but no use.

    I think maybe the below will solve the problem.
    Something wrong with my codes.
    System maybe not support the P1=Uart1 which stated by uPSD3200 FAMILY.
    There are so many chips which set with a little difference so have not a standard.

    I now to study about interrupt of system and try again.

    Thanks for your suggestion.

  • There is one thing that I have thought to be quite beneficial when it comes to code debugging, that is, write your own serial receive/transmit functions instead of using the provided printf() or putchar(), etc.,
    such that you can easily set breakpoints, poke bits and bytes. Here is what I would do,

    /*Call this function when you want to transmit*/
    void TxSData()
    {
       pTxBuffer=uTxBuffer;
       uTxByteCount=PACKET_LENGTH;
       TI1=1;
    }
    
    /*UART1 ISR*/
    void Serial1() interrupt y [using z]
    {
       if(RI1)
       {
         RI1=0;
         .
         //May need ptr sanity check
         *pRxBuffer++=SBUF1;
         .
       }
    
        if(TI1)
        {
           TI1=0;
           if(uTxByteCount--)
              SBUF1=*pTxBuffer++;		
        }
    }
    

    You may also want to use a timer to time out the inter-packet time, so you know a packet is ready in the receive buffer.

  • Alan,

    Thanks for your suggestion.

    I found the key to my problem. There are no fault with my code. But the hardware didn't set the RI2 and TI2 with 1 after receive and transmit a char. So the chip are waiting for set. So it had no result from uart2.

    Do you have some suggestion about this question.

    Thank you again.

  • Do you have some suggestion about this question?


    I am not sure what this question is. Apparently you have already concluded that your problem was due to a hardware failure. In that case, I will be very interested to know your diagnostic procedure.

  • For example:

       for(i=48;i<58;i++)  putchar(i);
       

    It only sent the char'0',and waited for the TI2 to be set. If you reset the chip, It still the same.

    If you set TI2 to be 1 after sent a char.
    It sent the char continually not right.

    So I think maybe something wrong with my hardware or Uart2 need to be set something by software.

    I used the Development Board to have my test.

    Thank you for your discussion.


  • Here is what I would do:

    TI2=0;         //Just in case TI2 has been set..
    for (i=48; i<58; i++) 
    {
       SBUF2=i;    //Not sure if SBUF2 is the right
                   //symbol name. Could be S2BUF?
       while(!TI2) //TI2 will be set by hardware
       {           //upon completion of one byte
       }
       TI2=0;
    }
    
    
    If this works, you may want to focus on that putchar() function.

  • I tried, but not successful.

    If you set TI2 to 1 by software. It passed.

    So sth wrong with the hardware. I believe it.

    Thank you for your help.

  • By the way, Which country are you in?