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.

MSP-EXP430FR2433: UART and SPI examples from driverlib don't work together

Part Number: MSP-EXP430FR2433
Other Parts Discussed in Thread: MSP430WARE

Problem: I want to use UART on UCA0 and SPI on UCA1. Joined examples from driverlib library. Once SPI is initialized, UART starts to work incorrectly.

Code:

#include "driverlib.h"
#include "Board.h"
#include "stdio.h"

#define STR_LEN 100

char str[STR_LEN];
uint8_t RXData = 0;
uint8_t check = 0;

void initClocks(void);
void initGpio(void);
void initSPI(void);
void sendUartMsg(char* str);
void initUart(void);
uint8_t stringLength(char* str);


void main(void)
{
    //Stop Watchdog Timer
    WDT_A_hold(WDT_A_BASE);

    initClocks();

    initGpio();

    // clocks should be initialized
    // appropriately
    initUart();
    initSPI();


    // Enable global interrupts
    __enable_interrupt();

    while (1)
    {
        sprintf(str, "abcdef\r\n");
        sendUartMsg(str);
        sprintf(str, "a\r\n");
        sendUartMsg(str);
        _delay_cycles(100000);
    }

    return;
}

void initClocks(void) {
    //Set ACLK = REFOCLK with clock divider of 1
    CS_initClockSignal(CS_ACLK,CS_REFOCLK_SELECT,CS_CLOCK_DIVIDER_1);
    //Set SMCLK = DCO with frequency divider of 1
    CS_initClockSignal(CS_SMCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1);
    //Set MCLK = DCO with frequency divider of 1
    CS_initClockSignal(CS_MCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1);
}

void initGpio(void) {
    //Configure UART pins
        GPIO_setAsPeripheralModuleFunctionInputPin(
            GPIO_PORT_UCA0TXD,
            GPIO_PIN_UCA0TXD,
            GPIO_FUNCTION_UCA0TXD
        );
        GPIO_setAsPeripheralModuleFunctionInputPin(
            GPIO_PORT_UCA0RXD,
            GPIO_PIN_UCA0RXD,
            GPIO_FUNCTION_UCA0RXD
        );

        GPIO_setAsPeripheralModuleFunctionInputPin(
                GPIO_PORT_P2,
                GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6,
                GPIO_PRIMARY_MODULE_FUNCTION
            );

        PMM_unlockLPM5();
}

void initUart(void) {
    //Configure UART
    //SMCLK = 1MHz, Baudrate = 115200
    //UCBRx = 8, UCBRFx = 0, UCBRSx = 0xD6, UCOS16 = 0
    EUSCI_A_UART_initParam param = {0};
    param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
    param.clockPrescalar = 8;
    param.firstModReg = 0;
    param.secondModReg = 0xD6;
    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_LOW_FREQUENCY_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);
}

void sendUartMsg(char* str) {
    uint8_t i;
    uint8_t length = stringLength(str);
    char curChar;

    for (i = 0; i < length; ++i) {

        curChar = str[i];

        //need to print first symbol correctly
        _delay_cycles(10000);

        // Load data onto buffer
        EUSCI_A_UART_transmitData(EUSCI_A0_BASE, curChar);

    }
}

uint8_t stringLength(char* str) {
    uint8_t i = 0;

    while (str[i] != '\0') {
        i++;
    }

    return i;
}

void initSPI(void) {
    //Initialize Master
        EUSCI_A_SPI_initMasterParam param = {0};
        param.selectClockSource = EUSCI_A_SPI_CLOCKSOURCE_SMCLK;
        param.clockSourceFrequency = CS_getSMCLK();
        param.desiredSpiClock = 500000;
        param.msbFirst = EUSCI_A_SPI_MSB_FIRST;
        param.clockPhase = EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT;
        param.clockPolarity = EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW;
        param.spiMode = EUSCI_A_SPI_3PIN;
        EUSCI_A_SPI_initMaster(EUSCI_A1_BASE, &param);

        //Enable SPI module
        EUSCI_A_SPI_enable(EUSCI_A1_BASE);

        //Clear receive interrupt flag
        EUSCI_A_SPI_clearInterrupt(EUSCI_A1_BASE,
              EUSCI_A_SPI_RECEIVE_INTERRUPT
              );

        // Enable USCI_A1 RX interrupt
        EUSCI_A_SPI_enableInterrupt(EUSCI_A1_BASE,
                             EUSCI_A_SPI_RECEIVE_INTERRUPT);
}

CCS Version: 11.0.0.00012

OS: Ubuntu

Thnaks in advance ;)

**Attention** This is a public forum