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/MSP430F5529: About using the SPI interface

Part Number: MSP430F5529
Other Parts Discussed in Thread: MSP-EXP430F5529LP

Tool/software: Code Composer Studio

Hi, I am new to msp430 and now I have a problem using msp430 SPI interface.

I want to test the SPI interface, but after I connect the logic analyzer with msp, the SPI signal was not sent out. the CLK and MOSI stay low all the time. I am wondering if it is the problem with the board. if yes, how can I test it. I actually tried the sample code of SPI provided by TI, but it doesn't work either.

Following is my code. it will repeatedly send 0x00 and 0xc8. 

#include "driverlib.h"
#define SPICLK                          1000000

uint8_t returnValue = 0x00;
void SendCodeSPI(uint8_t data);
void main (void)
{
    WDT_A_hold(WDT_A_BASE);
    //__enable_interrupt();
    //Set P1.1 for slave reset
    /*GPIO_setAsOutputPin(
                GPIO_PORT_P1,
                GPIO_PIN2
                );*/
    GPIO_setAsOutputPin(
                    GPIO_PORT_P1,
                    GPIO_PIN3
                    );
        //P3.5,4,0 option select
        GPIO_setAsPeripheralModuleFunctionInputPin(
            GPIO_PORT_P3,
            GPIO_PIN0+GPIO_PIN2
            );

        //Initialize Master
        USCI_B_SPI_initMasterParam param = {0};
        param.selectClockSource = USCI_B_SPI_CLOCKSOURCE_ACLK;
        param.clockSourceFrequency = UCS_getACLK();
        param.desiredSpiClock = SPICLK;
        param.msbFirst = USCI_B_SPI_MSB_FIRST;
        param.clockPhase = USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT;
        param.clockPolarity = USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW;
        returnValue =  USCI_B_SPI_initMaster(USCI_B0_BASE, &param);

        if (STATUS_FAIL == returnValue){
            return;
        }

        //Enable SPI module
        /*GPIO_setOutputHighOnPin(
                GPIO_PORT_P1,
                GPIO_PIN2
                );*/
        USCI_B_SPI_enable(USCI_B0_BASE);

        //Enable Receive interrupt

        //Wait for slave to initialize
        __delay_cycles(1000);
        GPIO_setOutputHighOnPin(
                                    GPIO_PORT_P1,
                                    GPIO_PIN3
                                    );
        while(1){
            USCI_B_SPI_transmitData(USCI_B0_BASE, 0x00);
            while(USCI_B_SPI_isBusy(USCI_B0_BASE));
            USCI_B_SPI_transmitData(USCI_B0_BASE, 0xC8);
            while(USCI_B_SPI_isBusy(USCI_B0_BASE));
        };
        /*while(true)
        {
            SendCodeSPI(0x00);
            __delay_cycles(1000000);
            SendCodeSPI(0xFF);
            __delay_cycles(1000000);
        }*/

}
void SendCodeSPI(uint8_t data)
{

    GPIO_setOutputLowOnPin(
                            GPIO_PORT_P1,
                            GPIO_PIN2
                            );
    __delay_cycles(1000);
    USCI_B_SPI_transmitData(USCI_B0_BASE, 0x00);
    while(USCI_B_SPI_isBusy(USCI_B0_BASE));
    USCI_B_SPI_transmitData(USCI_B0_BASE, data);
    while(USCI_B_SPI_isBusy(USCI_B0_BASE));
    GPIO_setOutputHighOnPin(
                            GPIO_PORT_P1,
                            GPIO_PIN2
                            );
    __delay_cycles(10000);
}

  • I don't see that symptom on my Launchpad, probing P3.0/P3.2. (The clock really is 32.8kHz, I just tried to fit too much on the screen.)

    I'm not sure what we're doing differently.

  • so this is my code running on your msp? if so, it should be the hardware problem 

  • Yes, I just pasted what you posted and put it on my Launchpad (MSP-EXP430F5529LP, for the keyword searchers).

    What platform are you using? Are you fairly certain you're using the right test points?

  • I use the msp430f5529lp either, and yes I test the signal on Pin3.0 and 3.2. the other functionalities seem good. The GPIO pin1.3 was set to high successfully, but the SPI? No.

  • I'm not sure what to suggest. The schematics don't show any real opportunities for conflicts.

    Do you get the same results if you use SMCLK instead of ACLK?

    Some people at the Forum have had success with mysterious problems by copying the source into a new project. (That's effectively what I did.) Implication was that they accidentally changed some project setting that they would never find again. Maybe it's worth a try?

    Do you have a spare Launchpad?

    [Edit: I forgot to ask: Do you have anything besides the Logic Analyzer connected to the board?]

  • I tried both ACLK and SMCLK, none of them works.

    I also created multiple projects imported the same code. still no work.

    logic analyzer is the only thing connected to the board.

    Actually I noticed one thing while testing, at the very beginning of the main function. the sentence: "WDT_A_hold(WDT_A_BASE);". If I delete it, the signal will not stay low all the time, it will have very wired "up and down" behavior.

    D1 and D2 are the CLK and MOSI. this kind of "pulse" will not be affected by the SPICLK I set. I don't know if it is a normal situation.

  • Something more wired happened.

    If I set the PIN 1.3 to LOW(the original code set it to high), it will not affect the state of pin 1.3, but the states of pin3.0 and 3.2 become HIGH and keep at it??!

    this board is just beyond any norm that I've known. I think I got to buy a new one.

    actually this is my second msp, the previous one cannot be loaded in any program, says "unknown device". 

  • The WDT thing I can explain -- the WDT is started automatically at Reset, so if you don't stop (or feed) it before it expires (32ms, I think) the MCU will reset (repeatedly). That's the pattern you saw.

    For the rest of the symptoms I don't have an explanation. If you have (or can get) a spare, that might be the fast path.Did this board ever work, i.e. did it just start malfunctioning?

  • Yes I just bought a new one yesterday. Much thank for your help.

**Attention** This is a public forum