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/MSP430F5244: SPI issue

Part Number: MSP430F5244

Tool/software: Code Composer Studio

Hi, I'm working on msp430F5244. My problem is when I run the controller at 1Mhz speed SPI works marginally and if I run the controller at 8Mhz SPI not at all working ,I pasted my code, Please help me someone where I'm wrong.

#include <msp430.h>
#include <stdint.h>
//#include "System_clk.h"
//#include "spi_function.h"
void systemClockConfigure_8Mhz()
{
    PMAPPWD = 0x02D52;                        // Enable Write-access to modify port mapping registers
    P4MAP7 = PM_MCLK;
    PMAPPWD = 0;                              // Disable Write-Access to modify port mapping registers

    UCSCTL3 = SELREF_2;                       // Set DCO FLL reference = REFO
    UCSCTL4 |= SELA_2 /*| SELS__DCOCLK*/;         // Set ACLK = REFO

    __bis_SR_register(SCG0);                  // Disable the FLL control loop
    UCSCTL0 = 0x0000;                         // Set lowest possible DCOx, MODx
    UCSCTL1 = DCORSEL_5;                      // Select DCO range 16MHz operation
    UCSCTL2 = FLLD_1 + 249;                   // Set DCO Multiplier for 8MHz
                                              // (N + 1) * FLLRef = Fdco
                                              // (249 + 1) * 32768 = 8MHz
    __bic_SR_register(SCG0);                  // Enable the FLL control loop

    // Worst-case settling time for the DCO when the DCO range bits have been
    // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
    // UG for optimization.
    // 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle
    __delay_cycles(250000);


    // Loop until XT1,XT2 & DCO stabilizes - In this case only DCO has to stabilize
    do
    {
      UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
                                              // Clear XT2,XT1,DCO fault flags
      SFRIFG1 &= ~OFIFG;                      // Clear fault flags
    }while (SFRIFG1&OFIFG);                   // Test oscillator fault flag

    UCSCTL4 |= SELS__DCOCLK | SELM__DCOCLK;         //MCLK and SMCLK=DCOCLK
}
void systemClockConfigure_1Mhz()
{
    PMAPPWD = 0x02D52;                        // Enable Write-access to modify port mapping registers
    P4MAP7 = PM_MCLK;
    PMAPPWD = 0;                              // Disable Write-Access to modify port mapping registers

    UCSCTL4 |= SELA_2;                        // Set ACLK = REFO
}

void SPI_UCB1Init()
{
    P4DIR |= BIT1 | BIT3 ;
    P4SEL |= BIT1 | BIT3 ;     // MISO and clk pin for spi
    UCB1CTL1 |= UCSWRST;
    UCB1CTL0 |= (UCMSB | UCSYNC | UCMST | UCCKPL); //3wire_spi + sync_mode + MSB first + master_mode    UCCKPH | | UCCKPL
    UCB1CTL1 |= UCSSEL__SMCLK;                    //SMCLK    UCSSEL__SMCLK 12MHz
    UCB1BR0 = 0x00;
    UCB1BR1 = 0x00;
    UCB1CTL1 &= ~UCSWRST;
}

void SPI_LCDTx(uint8_t value)
{
    UCB1TXBUF=value;
    while(!(UCB1IFG & UCTXIFG))
        ;
}
/*
 * main.c
 */
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
//    systemClockConfigure_1Mhz();
    systemClockConfigure_8Mhz();
    SPI_UCB1Init();
    while(1)
    {
        SPI_LCDTx('a');
        SPI_LCDTx('b');
        SPI_LCDTx('c');
    }
	return 0;
}

  • Hi Dhananjay,

    I see you're using port mapping for the SPI MISO and CLK pins but you haven't set the PMAPx register. Also you did not setup the MOSI line either. I recommend taking a look at the port mapping and SPI examples for this device that can be found here.

    Also, have you verified that SMCLK is running at 1MHz or 8MHz depending on your settings by outputting it to a GPIO and observing the frequency?

    Finally, please read through the Sections 2 and 4 of Solutions to Common eUSCI and USCI Serial Communication Issues on MSP430 MCUs. This will walk you through common SPI communication issues and how to solve them. Pay close attention to the section discussing maximum SPI communication speed. At 8MHz, there is a chance you are running too fast for the MSP, the slave, or maybe even both.

    Best regards, 
    Caleb Overbay

  • Hi Caleb,

    Sorry for mistakes, please check my code

    void SPI_UCB1Init()
    {
        P4DIR |= BIT1 | BIT3 ;
        P4SEL |= BIT1 | BIT3 ;     // MOSI and clk pin for spi
        UCB1CTL1 |= UCSWRST;
        UCB1CTL0 |= (UCMSB | UCSYNC | UCMST | UCCKPL); //3wire_spi + sync_mode + MSB first + master_mode    UCCKPH | | UCCKPL
        UCB1CTL1 |= UCSSEL__SMCLK;                    //SMCLK    UCSSEL__SMCLK 12MHz
        UCB1BR0 = 0x02;
        UCB1BR1 = 0x00;
        UCB1CTL1 &= ~UCSWRST;
    }

    yes, SMCLK frequency is 1MHz and 8MHz it's proper, I checked it using logic analyser since UCB1BR0 = 0x02 my clock speed is 4MHz so obviously SMCLK frequency is 8MHz.

    I checked the example codes in that link, no where they used PMAPx register for configuring SPI.

  • Hi Dhananjay,

    The SPI examples don't show use of PMAPx registers because they're not using port mapping. I brought this up because you're trying to use P4.1 and P4.2 for MOSI and CLK signals which is only achievable through port mapping. Looking at table 6-46 from the user's guide you can see that when the P4SEL bit is set for port 4, the P4MAPx also needs to be set appropriately:

    After making this change can you verify the following:

    • Ensure master and slave agree on clock polarity (inactive high)
    • Ensure master and slave agree on clock phase (data captured on trailing edge)
    • Ensure master and slave agree on MSB first
    • The slave is ready to receive data when the MSP starts communication

    Also, when communication doesn't work properly what are you seeing on the logic analyzer? Can you provide those shots for me as well?

    Best regards, 
    Caleb Overbay

  • I used port mappings also now, but no change in the output I found. please download details from the link

  • Hi Dhananjay,

    The link you provided is blocked while I'm behind the TI firewall. Can you post the details directly into your post?

    Were you able to verify the master and slave agree on the details I've listed above? Also did you perform the calculation specified in the application report to ensure you were within the max SPI communication speed for these two devices?

    Best regards,
    Caleb Overbay
  • Hi Caleb,

    I found problem is in my logic analyser. I tried loop back methods and displayed the received data through uart, It's working. I'm using that SPI for one LCD, It worked for 6months with no problem but recently LCD started not working often even though I didn't change any of my LCD and SPI code. I believe that there is no issue with SPI, may be it's problem with LCD. I will check what's the reason. Thank you for your help.

  • Hi Dhananjay,

    I'll keep this thread open for another week. If you have any further questions, don't hesitate to ask.

    Best regards,
    Caleb Overbay

**Attention** This is a public forum