1
\$\begingroup\$

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

\$\endgroup\$
9
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ code for(;;) { ptr = message; while(*ptr) { if(UART_LINE_STATUS & TX_COMPLETE) { UART_TX_BUF = (volatile unsigned char)(*ptr); ptr++; } } } code Please take a look at the datasheet ti.com/lit/ds/symlink/pga900.pdf. This processor doesn't have 'Tx buffer empty' or 'Tx fifo not full' bits. I modified the code in main as above .. so I am checking for the TX_COMPLETE bit is set or not in the UART_LINE_STATUS register. But still no output on the Tera-term. Please let me know. Thanks for your help \$\endgroup\$ – linuxstack Jul 1 '15 at 20:19
  • \$\begingroup\$ If you don't specify the chip in your question you get a generic answer... You could check for yourself once you get the hint where to look. The document you link to does not feel like a full datasheet/manual, but after a 60 seconds search I think COM_TXRDY might be what you need. \$\endgroup\$ – Wouter van Ooijen Jul 1 '15 at 21:26
  • \$\begingroup\$ @linux Wouter van Ooijen has the right suggestion, the cpu has internal status registers as well as interrupt lines available for you to poll the UART status. If you are running this on an embedded OS it likely has system calls for that. You have an ISR but it is doing nothing to affect your control flow. \$\endgroup\$ – crasic Jul 2 '15 at 6:29
  • \$\begingroup\$ Hello @Wouter van Ooijen thanks for the feedback, The datasheet just mentions that it has ARM Cortex M0 processor and nothing more than that. So I have no clue again what to understand from the COM_TX_STATUS register. What is the logic behind setting/checking for the COM_TXRDY bit set in COM_TX_STATUS. What is that I am missing to code in the ISR for Tx. Thanks \$\endgroup\$ – linuxstack Jul 2 '15 at 22:26
  • \$\begingroup\$ Hello @crasic thanks for the feedback, The datasheet just mentions that it has ARM Cortex M0 processor and nothing more than that. So I have no clue again what to understand from the COM_TX_STATUS register. What is the logic behind setting/checking for the COM_TXRDY bit set in COM_TX_STATUS. What is that I am missing to code in the ISR for Tx. Thanks \$\endgroup\$ – linuxstack Jul 2 '15 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.