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.

CCS/MSP430FR5994: UART + TIMERA Problems delay

Part Number: MSP430FR5994


Tool/software: Code Composer Studio

Hello,

I have a problem with a program using driverLib on the MSP430FR5994.

I have a timer A configured in Up mode to 1 second, it works fine (I have the interruption toggle a LED), but inside I send 5 bytes by serial (9600 - 8N1). 

The serial works fine, but the data arrives every two times the timer interrupts, In other words, In one interruption I don't see data on the serial, and on the next, I get the delayed data, and the new data at the same time.

Here is my code.

#include "driverlib.h"

void board_init()
{
    //Set DCO Frequency to 1MHz
    CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_0);

    //configure MCLK, SMCLK to be source by DCOCLK
    CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
    CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
    // Set GPIO pins as out
    GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0 + GPIO_PIN1);
    // Set GPIO pins as input
}

void timer_init()
{
    //Start timer in up mode sourced by SMCLK
    Timer_A_clearTimerInterrupt(TIMER_A0_BASE);

    Timer_A_initUpModeParam param = { 0 };
    param.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
    param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_40;
    param.timerPeriod = 25000;
    param.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;
    param.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE;
    param.timerClear = TIMER_A_DO_CLEAR;
    param.startTimer = false;

    Timer_A_initUpMode(TIMER_A0_BASE, &param);

    Timer_A_startCounter( TIMER_A0_BASE, TIMER_A_UP_MODE);

}

void uart_init()
{
    // Configure UART pins
    //Set P2.0 and P2.1 as Secondary Module Function Input.
    /*
     * Select Port 2d
     * Set Pin 0, 1 to input Secondary Module Function, (UCA0TXD/UCA0SIMO, UCA0RXD/UCA0SOMI).
     */
    GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P2,
    GPIO_PIN0 + GPIO_PIN1,
                                               GPIO_SECONDARY_MODULE_FUNCTION);

    // Configure UART
    EUSCI_A_UART_initParam param = { 0 };
    param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
    param.clockPrescalar = 6;
    param.firstModReg = 8;
    param.secondModReg = 20;
    param.parity = EUSCI_A_UART_NO_PARITY;
    param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
    param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
    param.uartMode = EUSCI_A_UART_MODE;
    param.overSampling = EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;

    if (STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, &param))
    {
        return;
    }

    EUSCI_A_UART_enable(EUSCI_A0_BASE);

    EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);

    // Enable USCI_A0 RX interrupt
    EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,
    EUSCI_A_UART_RECEIVE_INTERRUPT);                     // Enable interrupt
}


int main(void)
{
    //Stop watchDog Timer
    WDT_A_hold(WDT_A_BASE);
    board_init();
    timer_init();
    uart_init();

    // Activate all pins changes
    PMM_unlockLPM5();

    __bis_SR_register(GIE);

    GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
    __bis_SR_register(LPM0_bits);
    while (1)
    {
        __delay_cycles(250000); // (1/2) seg
        GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN1);
        EUSCI_A_UART_transmitData(EUSCI_A0_BASE, '@');

    }
}

char num[4];
int contador = 0;

#pragma vector = TIMER0_A0_VECTOR
__interrupt
void TIMER1_A0_ISR(void)
{
    if (contador > 9999)
        contador = 0;
    num[3] = (int) (contador % 10);
    num[2] = (int) ((contador / 10) % 10);
    num[1] = (int) ((contador / 100) % 10);
    num[0] = (int) ((contador / 1000));

    EUSCI_A_UART_transmitData(EUSCI_A0_BASE, num[0] + 48);
    EUSCI_A_UART_transmitData(EUSCI_A0_BASE, num[1] + 48);
    EUSCI_A_UART_transmitData(EUSCI_A0_BASE, num[2] + 48);
    EUSCI_A_UART_transmitData(EUSCI_A0_BASE, num[3] + 48);
    EUSCI_A_UART_transmitData(EUSCI_A0_BASE, 10);

    //Toggle P1.0
    GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
    contador++;
}

uint8_t RXData = 0, TXData = 0;

#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
    switch (__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG))
    {
    case USCI_NONE:
        break;
    case USCI_UART_UCRXIFG:
        RXData = EUSCI_A_UART_receiveData(EUSCI_A0_BASE);
        GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN1);
        switch (RXData)
        {
        case 'a':
            EUSCI_A_UART_transmitData(EUSCI_A0_BASE, 'h');
            EUSCI_A_UART_transmitData(EUSCI_A0_BASE, 'i');
            EUSCI_A_UART_transmitData(EUSCI_A0_BASE, '0');
            EUSCI_A_UART_transmitData(EUSCI_A0_BASE, '1');
            break;
        default:
            EUSCI_A_UART_transmitData(EUSCI_A0_BASE, RXData);
            break;
        }
        break;
    case USCI_UART_UCTXIFG:
        break;
    case USCI_UART_UCSTTIFG:
        break;
    case USCI_UART_UCTXCPTIFG:
        break;
    }
}

Thank you.

**Attention** This is a public forum