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.

MSP432P401R: uart halt

Part Number: MSP432P401R
Other Parts Discussed in Thread: MSP432WARE

when i use uart0 to send data to 2g modern and have a interrupt to received data transmitted to uart1 which is printf to pc

if (status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG)
    {
        u8RecvData = UART_receiveData(EUSCI_A0_BASE);
        UART_transmitData(EUSCI_A1_BASE, u8RecvData); 

but when i send data to 2g modern, the program is stopped in   MAP_UART_transmitData(EUSCI_A0_BASE, a_pu8Buf[u16Index]);

and i find that UCTXIFG is 0, and it halt because UCTXIFG is not 1, but i don't know who set UCTXIFG to 0

  • Hello,
    The UCTXIFG is reset automatically if a character is written to the UCAxTXBUF. The flag is set when the UCAxTXBUF is ready to accept another character. Please refer to section 22.3.15 of the TRM (www.ti.com/.../slau356f.pdf ),

    Regards,
    Chris
  • hi,thanks for your reply, i wonder reset means set 1 or set 0,UCTXIFG default is 1,that means reset is set 1?

  • and why UCTXIFG is 0 and didn't reset automatically, but uart1 already get the character in UCA0BUF and print to my pc? The whole program just stuck because the UCTXIFG is 0 and can't set 1
  • Reset means '0'. EUSCI_A0 and EUSCI_A1 are different peripherals. It might be helpful to understand how you have configured each peripheral. Can you provide any more of your source code?
    Chris
  • /*
     * -------------------------------------------
     *    MSP432 DriverLib - v4_00_00_11 
     * -------------------------------------------
     *
     * --COPYRIGHT--,BSD,BSD
     * Copyright (c) 2017, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    /******************************************************************************
     * MSP432 UART - PC Echo with 12MHz BRCLK
     *
     * Description: This demo echoes back characters received via a PC serial port.
     * SMCLK/DCO is used as a clock source and the device is put in LPM0
     * The auto-clock enable feature is used by the eUSCI and SMCLK is turned off
     * when the UART is idle and turned on when a receive edge is detected.
     * Note that level shifter hardware is needed to shift between RS232 and MSP
     * voltage levels.
     *
     *               MSP432P401
     *             -----------------
     *            |                 |
     *            |                 |
     *            |                 |
     *       RST -|     P1.3/UCA0TXD|----> PC (echo)
     *            |                 |
     *            |                 |
     *            |     P1.2/UCA0RXD|<---- PC
     *            |                 |
     *
     * Author: Timothy Logan
    *******************************************************************************/
    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>
    
    /* Standard Includes */
    #include <stdint.h>
    #include <stdio.h>
    #include <stdbool.h>
    
    /* UART Configuration Parameter. These are the configuration parameters to
     * make the eUSCI A UART module to operate with a 9600 baud rate. These
     * values were calculated using the online calculator that TI provides
     * at:
     *http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
     */
    const eUSCI_UART_Config uartConfig =
    {
            EUSCI_A_UART_CLOCKSOURCE_SMCLK,          // SMCLK Clock Source
            6,                                     // BRDIV = 78
            8,                                       // UCxBRF = 2
            32,                                       // UCxBRS = 0
            EUSCI_A_UART_NO_PARITY,                  // No Parity
            EUSCI_A_UART_LSB_FIRST,                  // LSB First
            EUSCI_A_UART_ONE_STOP_BIT,               // One stop bit
            EUSCI_A_UART_MODE,                       // UART mode
            EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION  // Oversampling
    };
    
    int main(void)
    {
        /* Halting WDT  */
        MAP_WDT_A_holdTimer();
    // MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
                 //GPIO_PIN1 , GPIO_PRIMARY_MODULE_FUNCTION);
        /* Selecting P1.2 and P1.3 in UART mode */
       // MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
                // GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
    	
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
                 GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
    
        /* Setting DCO to 12MHz */
        CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);
    
        /* Configuring UART Module */
        //MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig);
    MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig);
    
        /* Enable UART module */
        //MAP_UART_enableModule(EUSCI_A0_BASE);
    MAP_UART_enableModule(EUSCI_A0_BASE);
    
        /* Enabling interrupts */
        //MAP_UART_enableInterrupt(EUSCI_A1_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);
       //MAP_Interrupt_enableInterrupt(INT_EUSCIA1);
    	 MAP_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);
        MAP_Interrupt_enableInterrupt(INT_EUSCIA0);
        MAP_Interrupt_enableSleepOnIsrExit();
       MAP_Interrupt_enableMaster();   
        
        while(1)
        {
       
    			MAP_UART_transmitData(EUSCI_A0_BASE,'1');
    			
    			//MAP_Interrupt_enableSleepOnIsrExit();
    			//MAP_PCM_gotoLPM3InterruptSafe();
    			//MAP_PCM_gotoLPM0();
        }
    }
    
    
    
    
    /* EUSCI A0 UART ISR - Echoes data back to PC host */
    void EUSCIA0_IRQHandler(void)
    {
        uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE);
    
        MAP_UART_clearInterruptFlag(EUSCI_A0_BASE,status);
         
        if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG)
    
        {
    			MAP_UART_receiveData(EUSCI_A0_BASE);
           // MAP_UART_transmitData(EUSCI_A0_BASE, MAP_UART_receiveData(EUSCI_A0_BASE));
    			 // MAP_UART_transmitData(EUSCI_A0_BASE, 'p');
    			//MAP_UART_receiveData(EUSCI_A1_BASE);
    			//MAP_UART_transmitData(EUSCI_A1_BASE,MAP_UART_receiveData(EUSCI_A1_BASE));
        }
    
    }
    
    
    if my pc send data to uart0 and at the same time uart0 send data to pc this program wil stuck
    
    
    

  • at the same time 2g modern will send data to uart0, it's not about uart1, just when uart0 send and receive at the same time, it will stuck
  • > UART_clearInterruptFlag(EUSCI_A0_BASE, status);
    I recommend that you not do this.

    It's unnecessary, since reading RXBUF (a few lines later) will clear RXIFG (atomically).

    What it does do is invite a read-modify-write race which could clear a nascent TXIFG.
  • it didn't work the program is stuck when i send data to uart0
  • The code up above (that I quoted from) seems to have changed (completely). Which code are you referring to?

    In the new code, I recommend that you not do this:
    > MAP_UART_clearInterruptFlag(EUSCI_A0_BASE,status);
  • I suspect you also don't want this, but that's a separate thing:

    > MAP_Interrupt_enableSleepOnIsrExit();
  • yeah i find a simple way to reshow this bug, so i change it, i try to do what you told, but it stuck in receivedata, it will send to my pc 1111 until i send data to uart0 , and it stuck
  • yeah that's right
  • When I remove that line from your (new) code, it stops failing. I don't know what you and I are doing differently. (CCS 6.2.0, Black Launchpad, MSP432ware 3.50.00.02)
  • yeah,I try again , and this bug fixed, thanks a lot! it is the ti demos mistake me, it clear flag in the interrupt.

**Attention** This is a public forum