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.

MSPM0G3507: UART Configuration Confusion

Part Number: MSPM0G3507
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

Hi all,

I am completely new to programming MCU's and am stuck on UART. I have followed the "uart_echo_interrupts_standby_LP_MSPM0G3507_nortos_ticlang" example and deconstructed it from higher level macros to something that I can understand. My code and the example code look exactly the same except for the two "ti_msp_dl_config.h" files. That seems to be the difference maker but I can't change that file. Can someone please tell me where I am going wrong with configuring UART? I posted my code below.

#include "ti_msp_dl_config.h"
static const DL_UART_Main_ClockConfig gUART_0ClockConfig = {
    .clockSel    = DL_UART_MAIN_CLOCK_LFCLK,
    .divideRatio = DL_UART_MAIN_CLOCK_DIVIDE_RATIO_1
};

static const DL_UART_Main_Config gUART_0Config = {
    .mode        = DL_UART_MAIN_MODE_NORMAL,
    .direction   = DL_UART_MAIN_DIRECTION_TX_RX,
    .flowControl = DL_UART_MAIN_FLOW_CONTROL_NONE,
    .parity      = DL_UART_MAIN_PARITY_NONE,
    .wordLength  = DL_UART_MAIN_WORD_LENGTH_8_BITS,
    .stopBits    = DL_UART_MAIN_STOP_BITS_ONE
};
volatile uint8_t gEchoData = 0;
int main(void)
{
    //SYSCFG_DL_init()
    DL_GPIO_reset(GPIOA);
    DL_GPIO_reset(GPIOB);
    DL_UART_reset(UART0);

    DL_GPIO_setPins(GPIOA, DL_GPIO_PIN_10 | DL_GPIO_PIN_11);
    DL_GPIO_enableOutput(GPIOA, DL_GPIO_PIN_10);

    DL_GPIO_enablePower(GPIOA);
    DL_GPIO_enablePower(GPIOB);
    DL_UART_enablePower(UART0);

    DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM21, IOMUX_PINCM21_PF_UART0_TX);
    DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM22, IOMUX_PINCM22_PF_UART0_RX);

    DL_GPIO_initDigitalOutput(IOMUX_PINCM1);
    DL_GPIO_initDigitalOutput(IOMUX_PINCM37);

    DL_GPIO_setPins(GPIOA, DL_GPIO_PIN_0 | DL_GPIO_PIN_15);
    DL_GPIO_enableOutput(GPIOA, DL_GPIO_PIN_0 | DL_GPIO_PIN_15);

    /* Module-Specific Initializations*/

    DL_UART_setClockConfig(UART0, (DL_UART_Main_ClockConfig *) &gUART_0ClockConfig);

    DL_UART_init(UART0, (DL_UART_Main_Config *) &gUART_0Config);
    /*
     * Configure baud rate by setting oversampling and baud rate divisors.
     *  Target baud rate: 9600
     *  Actual baud rate: 9576.04
     */
    DL_UART_setOversampling(UART0, DL_UART_OVERSAMPLING_RATE_3X);
    DL_UART_setBaudRateDivisor(UART0, 1, 9);

    /* Configure Interrupts */
    DL_UART_enableInterrupt(UART0,DL_UART_INTERRUPT_RX);

    DL_UART_enable(UART0);
    DL_GPIO_enableOutput(GPIOA, DL_GPIO_PIN_10);

    NVIC_ClearPendingIRQ(UART0_INT_IRQn);
    NVIC_EnableIRQ(UART0_INT_IRQn);

    DL_SYSCTL_enableSleepOnExit();

    while (1) {
        __WFI();
    }
}

void UART_0_INST_IRQHandler(void)
{
    switch (DL_UART_getPendingInterrupt(UART0)) {
        case DL_UART_IIDX_RX:
            DL_GPIO_togglePins(GPIOA,DL_GPIO_PIN_0 | DL_GPIO_PIN_15);
            gEchoData = DL_UART_receiveData(UART0);
            DL_UART_transmitData(UART0, number);
            break;
        default:
            break;
    }
}

  • Hi,

    ti_msp_dl_config.h is generated automaticlly from Sysconfig.

    You can not change it manually.

    Regards,

    Zoey

  • Ah. Thanks Zoey. My issue seems to be that the ti_msp_dl_config.h in the example refers to some code that is part of the configuration of the UART. Otherwise, my posted code is identical, but it doesn't work.

  • Ah... Sorry for misunderstanding...How do you judge it doesn't work? By LED?

    And please try to add delay after enable power. And you don't need to add 56 line enable output command, as the port is served as UART function not GPIO.

  • By the way, what's the number in line 74. Where do you define it?

  • Thank you for the catch. That was an old variable. However, the Putty software I am using is still not getting any responses back from the UART

  • Yes, an LED toggles every time data is received by the UART. I use putty which is software that has my pc act like a terminal. I have added a delay and deleted line 56 due to redundancy. Does the order of the code matter here? Should I be powering the UART first before trying to configure it?

  • I got it to work! I had to rearrange the macros to follow these steps from the manual:

    1. Configure RX and TX pin functions by using the IOMUX registers.

    2. Reset the peripheral using UARTx.RSTCTL register

    3. Enable the power to UART peripheral using the UARTx.PWREN register

    4. Select the UART function clock source and divide options using UART.CLKSEL and UART.CLKDIV registers.

    5. Disable the UART by clearing the UART.CTL0.ENABLE bit.

    6. Use the baud-rate equation in Section 16.2.3.4 to calculate the UARTx.IBRD and UARTx.FBRD registers.

    7. Write the integer portion of the BRD to the UART.IBRD register.

    8. Write the fractional portion of the BRD to the UART.FBRD register.

    9. Write the desired oversampling and FIFO configuration to the UART.CTL0 register

    10. Write the desired serial parameters to the UART.LCRH register.

    11. Enable the UART by setting the UART.CTL0.ENABLE bit.

    And then i had to change the interrupt name to "UART0_IRQHandler".