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.

MSP432 PWM and UART example issue

Other Parts Discussed in Thread: MSP432WARE

Hello all,

So I'm trying to combine two of the examples from the MSP432 Ware from the resource explorer. The two examples are: timer_a_pwm_mode and uart_pc_echo_12mhz_brclk using the driver library peripherals. What I'm trying to do by the end of the example is control the duty cycle of the PWM signal through a UART command, but for now I would be happy receiving the echo and setting the duty cycle as the examples do currently. Unfortunately, when I initially tried to combine the programs I received the error:

"

Error connecting to the target:
(Error -614 @ 0x0)
The target indicates there is an error condition from a previous SWD
request. Clear the error the condition, and try the SWD request again.
(Emulation package 6.0.407.3)

"

But when I run the examples individually, they work as intended. I'm still rather new to the driverlib and C programming, so I'm not sure what issues I am causing. I have included the code which I had stated before is just the two examples put together directly.

/* DriverLib Includes */
#include "driverlib.h"

/* Standard Includes */
#include <stdint.h>

#include <stdbool.h>
/* Timer_A PWM Configuration Parameter */
Timer_A_PWMConfig pwmConfig =
{
        TIMER_A_CLOCKSOURCE_SMCLK,
        TIMER_A_CLOCKSOURCE_DIVIDER_1,
        3200,
        TIMER_A_CAPTURECOMPARE_REGISTER_1,
        TIMER_A_OUTPUTMODE_RESET_SET,
        320
};

const eUSCI_UART_Config uartConfig =
{
        EUSCI_A_UART_CLOCKSOURCE_SMCLK,          // SMCLK Clock Source
        78,                                     // BRDIV = 78
        2,                                       // UCxBRF = 2
        0,                                       // 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();

	    /* Selecting P1.2 and P1.3 in UART mode */
	    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
	            GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);

	    /* Setting DCO to 12MHz */
	    MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);

	    /* Configuring UART Module */
	    MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig);

	    /* Enable UART module */
	    MAP_UART_enableModule(EUSCI_A0_BASE);

	    /* Enabling interrupts */
	    MAP_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);
	    MAP_Interrupt_enableInterrupt(INT_EUSCIA0);
	    MAP_Interrupt_enableSleepOnIsrExit();
	    MAP_Interrupt_enableMaster();

    /* Setting MCLK to REFO at 128Khz for LF mode
     * Setting SMCLK to 64Khz */
	MAP_CS_setReferenceOscillatorFrequency(CS_REFO_128KHZ);
    MAP_CS_initClockSignal(CS_MCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
    MAP_CS_initClockSignal(CS_SMCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_2);
    MAP_PCM_setPowerState(PCM_AM_LF_VCORE0);

    /* Configuring GPIO2.4 as peripheral output for PWM  and P6.7 for button
     * interrupt */
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4,
            GPIO_PRIMARY_MODULE_FUNCTION);
    MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
    MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1);
    MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);

    /* Configuring Timer_A to have a period of approximately 500ms and
     * an initial duty cycle of 10% of that (3200 ticks)  */
    MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);

    /* Enabling interrupts and starting the watchdog timer */
    MAP_Interrupt_enableInterrupt(INT_PORT1);
    MAP_Interrupt_enableSleepOnIsrExit();
    MAP_Interrupt_enableMaster();

    /* Sleeping when not in use */
    while (1)
    {
        MAP_PCM_gotoLPM0();
    }
}

/* Port1 ISR - This ISR will progressively step up the duty cycle of the PWM
 * on a button press
 */
void PORT1_IRQHandler(void)
{
    uint32_t status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P1);
    MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, status);

    if (status & GPIO_PIN1)
    {
        if(pwmConfig.dutyCycle == 28800)
            pwmConfig.dutyCycle = 3200;
        else
            pwmConfig.dutyCycle += 3200;

        MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);
    }
}

/* 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_transmitData(EUSCI_A0_BASE, MAP_UART_receiveData(EUSCI_A0_BASE));
    }

}

Any help is appreciated! 

 

  • Hello Thomas,

    I was able to build the code you provided without any issues, furthermore the "Error connecting to the target" message implies that there is an issue with the hardware as compared to the software. Please check the connections between the FET device and target board, you might also want to do a factory reset as discussed in Section 8.1 of the CCS 6.1+ for MSP432 User's Guide: www.ti.com/.../slau575e.pdf

    Please make sure to change your startup_msp432p401r_ccs.c file to account for both PORT1_IRQHandler and EUSCIA0_IRQHandler: e2e.ti.com/.../1545615

    Regards,
    Ryan
  • So I was able to factory reset the microcontroller and add the interrupt vectors to the startup file, and the error message disappeared. Unfortunately, I then try to run the code above and receive no echo. I tried the UART example to check that the port is still working, and it is not. I then restart my computer to run the example. After restarting, the example works again, but the error message is back on the test program.

    I've repeated the process multiple times and have received the same result each time. Not sure what I may be doing incorrectly.
  • It seems like something could be wrong with the test program settings, could you try modifying the working UART example to include your timer functionality and see if the error message does not appear?

    Regards,
    Ryan
  • So I modified the UART example from MSP432WARE that I mentioned before to include the timer portions and corrected the startup file to include the necessary vector. After modifying the example, I did not receive the error message, now the echo portion does not work. Is it possible that the two portions are trying to overwrite each other? Thank you for your help.
  • Most likely not, now you just need to account for changes you made that could have damaged your UART communication (changing SMCLK is definitely a factor).

    Regards,
    Ryan
  • The driver library user guide doesn't expressly say what clocks you can use for the PWM signal. Is there a way to set the PWM configuration to not interfere with the UART communication? Or is it possible to configure the PWM signal using a different clock?
  • Thomas,

    Since you are using SMCLK as the clock source for your UART communication, that affects how you set the baudrate. Those 3 numbers (BRDIV/clockPrescalar, UCxBRF/firstModReg, and UCxBRS/secondModReg) in the uartConfig somehow control how the clock is divided up to set your baudrate. If you change the frequency of your clock source, you must then change those numbers if you want to keep the same baudrate. There is a handy calculator ( software-dl.ti.com/.../index.html ) that takes your clock frequency and desired baudrate and gives you the proper values for BRDIV/clockPrescalar, UCxBRF/firstModReg, and UCxBRS/secondModReg, as well as your oversampling (the last line of your uartConfig).

    Regards,
    Matt

  • That worked! I'm still having trouble receiving the data back in a timely manner, but have been debugging the system using the LEDs to see where the code gets stuck. Final question, is there example of parsing an incoming message using the driver libraries?

**Attention** This is a public forum