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

MCB2300 UARTs question

Hi,
I bought MCB2300 to start my project now.
Without any modifications on the UART demo code,
MCB2300 can work properly on UART0 and UART1(I connected UART0/UART1 to PC with Hyperterminal, typing a character, MCB2300 can sent back same character).
But I tried to keep sending a character from MCB2300 to PC on UARt1, hypterminal only recivered one sending.Using UART0 has the same problem.
following is my modification, anybody can help me to figure out what's wrong? highlight are my changes.
Thanks
Jack

int main (void)
{
    UARTInit(0, 115200);        /* baud rate setting */
    UARTInit(1, 115200);        /* baud rate setting */


    UART1Count =1;
    UART1Buffer[0] = 0x41;


  while (1)
  {
        /* Loop forever */
        if ( UART0Count != 0 )
        {
          U0IER = IER_THRE | IER_RLS;                   /* Disable RBR */
          UARTSend( 0, (BYTE *)UART0Buffer, UART0Count );
          UART0Count = 0;
          U0IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */
        }
        if ( UART1Count != 0 )
        {
          U1IER = IER_THRE | IER_RLS;                   /* Disable RBR */
          UARTSend( 1, (BYTE *)UART1Buffer, UART1Count );
          UART1Count = 0;
          U1IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */
        }
  }
  return 0;
}

void UARTSend( DWORD portNum, BYTE *BufferPtr, DWORD Length )
{
  if ( portNum == 0 )
  {
    while ( Length != 0 )
    {
          /* THRE status, contain valid data */
          while ( !(UART0TxEmpty & 0x01) );
          U0THR = *BufferPtr;
          UART0TxEmpty = 0;     /* not empty in the THR until it shifts out */
          BufferPtr++;
          Length--;
        }
  }
  else
  {
        while ( Length != 0 )
    {
          /* THRE status, contain valid data */
          while ( !(UART1TxEmpty & 0x01) );
          U1THR = *BufferPtr;
          UART1TxEmpty = 0;     /* not empty in the THR until it shifts out */

          //BufferPtr++;        /always to send UART1Buffer[0] */

          Length--;
    }
  }
  return;
}

  • Hi,
    I bought MCB2300 to start my project now.
    Without any modifications on the UART demo code,
    MCB2300 can work properly on UART0 and UART1(I connected UART0/UART1 to PC with Hyperterminal, typing a character, MCB2300 can sent back same character).
    But I tried to keep sending a character from MCB2300 to PC on UARt1, hypterminal only recivered one sending.Using UART0 has the same problem.
    following is my modification, anybody can help me to figure out what's wrong? highlight are my changes.
    Thanks
    Jack

    int main (void)
    {
        UARTInit(0, 115200);        /* baud rate setting */
        UARTInit(1, 115200);        /* baud rate setting */
    
    
        UART1Count =1;
        UART1Buffer[0] = 0x41;
    
    
      while (1)
      {
            /* Loop forever */
            if ( UART0Count != 0 )
            {
              U0IER = IER_THRE | IER_RLS;                   /* Disable RBR */
              UARTSend( 0, (BYTE *)UART0Buffer, UART0Count );
              UART0Count = 0;
              U0IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */
            }
            if ( UART1Count != 0 )
            {
              U1IER = IER_THRE | IER_RLS;                   /* Disable RBR */
              UARTSend( 1, (BYTE *)UART1Buffer, UART1Count );
    
              //UART1Count = 0;
    
              U1IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */
            }
      }
      return 0;
    }
    
    void UARTSend( DWORD portNum, BYTE *BufferPtr, DWORD Length )
    {
      if ( portNum == 0 )
      {
        while ( Length != 0 )
        {
              /* THRE status, contain valid data */
              while ( !(UART0TxEmpty & 0x01) );
              U0THR = *BufferPtr;
              UART0TxEmpty = 0;     /* not empty in the THR until it shifts out */
              BufferPtr++;
              Length--;
            }
      }
      else
      {
            while ( Length != 0 )
        {
              /* THRE status, contain valid data */
              while ( !(UART1TxEmpty & 0x01) );
              U1THR = *BufferPtr;
              UART1TxEmpty = 0;     /* not empty in the THR until it shifts out */
    
              //BufferPtr++;        /always to send UART1Buffer[0] */
    
              Length--;
        }
      }
      return;
    }
    

  • I don't understand your question.

    It seems like you want to send multiple characters.

    But your count is 1, and after sending one character you set the count to zero which means your infinite loop doesn't have anything to do anymore.

    It would be best if you rewrote the code to be more self-contained. Either hide the output using an interrupt handler where you print into a ring buffer. Or at least create a free-standing "send_string" function. You do not want your main() to have to fiddle with UART flags directly.

  • my first post is not roght, pleas see my second post

    Thanks

    Jack

  • Thank you for your reply quickly.
    I just wanted to keep sending an "A"charcter to PC.
    I tried on UART0 and UART1, both Ports are the same, just received one char, and hangs at

     while ( !(UART1TxEmpty & 0x01) );
    

    in send function.if I set a breakpoint after sending in main:

    
    if ( UART1Count != 0 )
            {
              U1IER = IER_THRE | IER_RLS;                   /* Disable RBR */
              UARTSend( 1, (BYTE *)UART1Buffer, UART1Count );
              //UART1Count = 0;
    //breakpoint here:
              U1IER = IER_THRE | IER_RLS | IER_RBR;
            /* Re-enable RBR */
            }
    


    I can get char on PC side every time

    Thanks

    jack

  • Hello Jack Yang,

    I assume that UART0TxEmpty is a global variable. Is it ever set to 1?

    You can use

    while (!(U0LSR & 0x20));
    


    instead of

    while ( !(UART0TxEmpty & 0x01) );
    


    to check if the Transmit Holding Register is empty.

    Best Regards,
    Martin Guenther