I am new to ARM CORTEX M0. I am trying to use the Tx pin of UART as debug port.
If I use the XDS200 debugger to step through the code, I am able to see the characters and I can see "Hello World" printed neatly on the Tera-Term through COM port.
But if I let the microcontroller run by itself I don't see any output and the probe connected on the Tx pin shows constant high.
I think only after using the debugger and stepping through the code the signals appear but not exactly representing "Hello World". Following is the part of output I logged from Tera-Term and this is repetitive:
/***********************************************************/
W
oldo
W
oldo
Hrl
Well WHWelo
WHWelo
WHrld HoHrl WHoell Weold
olrl WHrllo
Welllo
oell Hrldo
Welo o
oelo o
oelo Hrl
Welo
/***********************************************************/
Following is the main() function code.
/***********************************************************/
void main(void)
{
Configure_peripheral(); /*This function call initializes all the required interrupts and global variables etc... */
char message[] = "Hello World \n";
char *ptr;
for(;;)
{
ptr = message;
while(*ptr)
{
UART_TX_BUF = (volatile unsigned char)(*ptr);
ptr++;
}
}
}
/***********************************************************/
Following is the UART Interrupt Service Routine code
/***********************************************************/
interrupt void uart_isr(void)
{
if(UART_INTERRUPT_STATUS & UART_TXCOMPLETE_I)
{
/* Clear UART_TXCOMPLETE_I bit */
UART_INTERRUPT_STATUS |= 0x02;
/*datasheet : http://www.ti.com/lit/ds/symlink/pga900.pdf*/
/*As per PGA900 datasheet : TX_COMPLETE is cleared when the UART_TX_BUF is written*/
/* Read UART_LINE_STATUS for errors */
UART_Line_Status = UART_LINE_STATUS;
/* Transmit flag set here */
UART_Flag_Tx = 1;
}
}
Could someone please help me understand what I am missing to get the expected string "Hello World" printed instead of jumbled up text. I am using a USB-Serial transceiver with operating voltage of 0-3.3v. Thanks
Best Answer
You are putting characters into the transmit buffer as fast as you can, without checking whether the UART is ready to accept a next character. Hence a lot of characters are lost, and what the PC receives is a more or less random subset of the characters you attempt to transmit.
Check for the 'tx buffer empty' or 'tx fifo not full' bits. Before assigning a next character to the Tx buffer, first wait for one of those bits.