This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2955: UART multiple bytes transmit Usage

Guru 24520 points

Hi Community member,

Please provide your comments for my request.

[Request]

  Is there any way to set the UART transmit interval timing without using timer?

[Background]

Now my customer used the UART function and set this function via Grace.

    Setting for UART:  SMCLK source(2MHz)/8bit/Parity:none/115200bps/1stop

Regarding Sample code of UART, check the TX buffer ready and send data if ready such as below.

      // USCI_A0 TX buffer ready?
    while (!(IFG2 & UCA0TXIFG)); // Poll TXIFG to until set
    UCA0TXBUF = UCA0RXBUF;       // TX -> RXed character
    /* USER CODE END (section: USCI0RX_ISR_HOOK) */

There is any problem for UART operation if the data is 1byte. However, if sent some data such as below, had a receive error with overwhelming probability since subsequent 2byte.

    while (!(IFG2&UCA0TXIFG));     // USCI_A1 TX buffer ready?
    UCA0TXBUF = send_data1;        //
    while (!(IFG2&UCA0TXIFG));     // USCI_A1 TX buffer ready?
    UCA0TXBUF = send_data2;        //

If inserted the wait between sending command, the data could receive without an error. However, if this code used, MSP430 could not do any other work in order to use the resource by delay cycle.

     while (!(IFG2&UCA0TXIFG));     // USCI_A1 TX buffer ready?
    UCA0TXBUF = send_data1;        //
    _delay_cycles(256);
    while (!(IFG2&UCA0TXIFG));     // USCI_A1 TX buffer ready?
    UCA0TXBUF = send_data2;        //

In addition to this, they have spent the all Timers of MSP430.

So, we need to proposal other solution without using timers and delay cycle.

If you have any questions, please let me know.

Best regards.

Kaka

  • Hello Kaka,

    Is your customer using watchdog timer?

    I think that you can use watchdog timer as interval timer if your customer doesn't use watchdog module in MSP430.

     

    Best Regards,

    Richard Park

  • Kato Motoki said:

    There is any problem for UART operation if the data is 1byte. However, if sent some data such as below, had a receive error with overwhelming probability since subsequent 2byte.

        while (!(IFG2&UCA0TXIFG));     // USCI_A1 TX buffer ready?
        UCA0TXBUF = send_data1;        //
        while (!(IFG2&UCA0TXIFG));     // USCI_A1 TX buffer ready?
        UCA0TXBUF = send_data2;        //

    The CPU is running from MCLK, and the UART is running on a clock that is SMCLK divided by some value to get a bit-rate clock. The UART sets/clears at the bit-rate clock rate, which is slower than the CPU clock. So, as you can probably see, the CPU gets to the instruction to check UCA0TXIFG flag BEFORE the UART has had a chance to update the flag. That is why it works with the __delay_cycles() call and not without it.

    Kato Motoki said:
    If inserted the wait between sending command, the data could receive without an error. However, if this code used, MSP430 could not do any other work in order to use the resource by delay cycle.

    To be accurate, the MSP430 can't do any work while it's waiting for the UART TX buffer to be ready either (the while(!(...)) code).

    The better way to handle this is to use a transmit buffer queue that you put values in, and handle the UART UCA0TXIFG flag in an ISR where you simply get the next character from the queue and stuff it into the UART. Then there is no while loop, no __delay_cycles() loop or anything.

**Attention** This is a public forum