We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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; }
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