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.

SPI driver problem MSP430

Other Parts Discussed in Thread: MSP430F5309

Hi All,

I am new to MSP430. - MSP430F5309

I am using 4 - pin SPI in my code. With the evaluation board, I was unable to see any clock or any data on the Tx pin and the clock when a data is getting transmitted on the SPI.

My code is like this.

/* Enable the sPI to work in master mode */
    UCB1CTL0 |= UCMST;
    /* Select the 4 pin SPI mode with UCSTE active low
     * Active low is required since for the aDC the CS bit
     * is active low.
     */
    UCB1CTL0 |= UCMODE1;

    /* Select synchronous mode with MSB first */
    UCB1CTL0 |= (unsigned char)(UCSYNC + UCMSB);

    /* Select SMCLK as the clock for this peripheral - 12 MHz */
    UCB1CTL1 |= UCSSEL1;

    /* Select the divider as 24 i.e., the CLK is 12M/24 = 0.5 MHz */
    UCB1BR0 = 24;
    UCB1BR1 = 0;

    /* Set UCB1STE as output - P4.3 pin */
    P4DIR |= BIT3;

    /* Start the conversion for the ADC */
    P4OUT &= ~BIT3;

    //PM_UCB1STE = 0;


    /* Initialize the ADC in auto -1 mode - low byte*/
    UCB1TXBUF = 0x28;

    /* Wait till the transfer is over */
    while(UCB1STAT & UCBUSY == UCBUSY)
    {
        UCB1STAT &= ~UCBUSY;
    }

    __delay_cycles(1000);

    /* High byte for auto -1 mode */
    UCB1TXBUF = 0x40;

    /* Wait until transmission is over */
    while(UCB1STAT & UCBUSY == UCBUSY)
    {
        UCB1STAT &= ~UCBUSY;
    }

    __delay_cycles(1000);
    /* Stop the conversion */
    P4OUT |= BIT3;

Since I am using UCB1, the STE pin of this is defined as PM_UCB1STE. So how to set this bit to start SPI transfer?

Or is there anything wrong in my code.?

Note: My SPI pins are unconnected and I am not initializing any clock assuming it will take 1 MHz as the default clock

Thanks

Chaithra

  • The code doesn't set the any PxSEL bits, which is required to select pins for use by the UCB1 module.

    The PxSEL bits are cleared at device reset, which means the pins are just GPIO. See the MSP430x5xx/MSP430x6xx Family User's Guide SLAU208J and MSP430F530x datasheet SLAS677B for details

     Which pins are you using for SPI? 

  • Correct. There was a problem in the code. After that I selected peripheral selection for those pins and used port mapping register also. 

    Now, it is working fine with the eval board. One more thing, I used IFG bit to read the status instead of STAT bit as indicated in the example codes.

    Thannks

  • Chaithra Bharadwaj said:
    I used IFG bit to read the status instead of STAT bit as indicated in the example codes.

    TXIFG bit is set when TXBUF is ready to receive the next byte. It does not mean that the former byte has been sent (in fact, it just starts sending).

    Checking for UCBUSY is the only way to know that a transmission is really done. However, to make use of the double-buffering on transmissions with more than one byte length, of coure checking the TXIFG bit is the best way for high throughput. UCBUSY is only required to know that the last transmission is really done and e.g. the chip select can be de-asserted.

  • Hello Gross,

    I checked with BUSY flag also. Its working now. Thanks for the advice. 

**Attention** This is a public forum