Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Polling register bit and hardware UART on MSP430G2553

$
0
0

I have a very simple question regarding polling register bits. The question arises in  the context of UART transmission on the msp430g2553 with a hardware UART module.

Serial transmission is implemented by sending the char string to a function "SendData". This function copies the data into a global buffer, and sends the first character to the TX buffer. After that, the USCI TX interrupt loads each additional character unto the buffer. When the newline is reached, the TX interrupt is disabled and the newline is loaded into the buffer.

I need to effectively stop the microprocessor while the data is being sent, otherwise additional data will likely be copied over the incomplete transmission. I am not interested in going into low power mode, because I have a fairly complex PWM dithering routine running in the background, and the processor is constantly servicing interrupts from that anyway.

I have a "while" loop in the SendData function to loop until the data is sent. I was attempting to pole the TX interrupt enable bit, but for some reason that would not keep the micro in the while loop. I also attempted to read the data buffer again, as shown in the highlighted section below, but that did not work.

This is likely a simple oversight, but if anyone has any suggestions they would be appreciated! It seems very unnecessary to use an additional data value the way I have used the "test" variable to determine when the newline is sent.

As a side note, are there any libraries available for hardware UART with the MSP430? When I first wrote this I was unable to find any, so I pieced one together with the send function as well as integer to asci conversion. Again, this is a side note. I am not looking for examples, just wondered if TI has any complete libraries.

Thank you in advance!

Chris

/*
 *  ======== UART String Transmission Function ========
 */
void SendData(char str[])
{
    iread = 0;                                //Set index value to zero
    test = 1;                                   //test is a global variable
    DataBuffer[0] = 0;                         //Clear data buffer
    strcpy(DataBuffer, str);                //Copy string into global data buffer

    UCA0TXBUF = DataBuffer[iread++];        // Start TX Interrupt with a TX
    IE2 |= UCA0TXIE;                        // Enable USCI_A0 TX interrupt

    while(test)                                 //Loop until the newline has been sent (see interrupt below)


    // Either of thses two approaches should have worked, but they did not...
    //while(IE2 & (1<<UCA0TXIE))    Loop while the TX interrupt is enabled. It is disabled below when '\n' is sent.
    //while(!(DataBuffer[iread] =='\n'))    Loop while the data buffer at iread is not '\n'
    {
            //Loop while most of text is sent. When the newline is loaded wait 1.1ms so that it can send.
    }
    _delay_cycles(40000);        //Delay 1.1ms (16000) so that \n can be sent, plus extra
                                //System clock running at 16MHz
}

/*
 *  ======== USCI A0/B0 TX Interrupt Handler Generation ========
 */
#pragma vector=USCIAB0TX_VECTOR                // Handler is run when the TX interrupt is thrown indicating that
                                            //the byte in the TX buffer has finished being sent.
__interrupt void USCI0TX_ISR_HOOK(void)
{
    if(DataBuffer[iread] =='\n' )              // If newline has been reached, transmission is over so disable TX interrupt and send last byte (newline).
    {                                        // Newline is still sent below.
    IE2 &= ~UCA0TXIE;                          // Disable USCI_A0 TX interrupt.
    test = 0;                                // Set indicator bit to zero. I should not need to use a separate bit??
    }

    UCA0TXBUF = DataBuffer[iread++];        // Load next character into TX buffer.
}


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>