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.

MSP430f5508 & SPI

Other Parts Discussed in Thread: MSP430F5508, GRACE, ADS1259


I'm new at this and a would like to know when I do the initialization of spi:

What is the secondary function ?

What is doing this line of code?

P4SEL |= BIT3+BIT4;       // P4.3,4 option select  

P4SEL |= BIT0;     // P4.0 option select

How to set a bit in '0'?

From datasheet those pins have 3 functions? how to chose USCI_A1 UART mode?

Regards David.

  • Hi,

    A pin could work as primary function and secondary function.

    Primary function is basically as GPIO.

    Secondary function, in this case, ti could be UART or SPI.

    David V said:

    P4SEL |= BIT3+BIT4;       // P4.3,4 option select  

    P4SEL |= BIT0;     // P4.0 option select

    How to set a bit in '0'?

    With this line you are selecting the secondary function of the pins 3, 4 y 0 of the port 4. That is to say, these pins will be used as UART or SPI pins. What in particular? It depends on the serial module configuration that you have entered. Take a look at users' guide and code examples, they can help you a lot.

  • Thanx ,

    One question, are there functions for SPI init , send data , receiver data for MSP430f5508?

    Regards David.

  • Hi,

    There are examples of SPI initialization in code examples or you could use GRACE software to create it (I have never used it). For sending or receiving, there are some basic principles in code examples, and maybe someone has could write some function to do it. In negative case, you will have to code your custom functions to initialize and store the TX'd and RX'd data, using for example a ring buffer or another solution that you consider.

  • Hi,

    Can someone check the code ? ADS1259 MSP430F5508 communication trough SPI

    #include <msp430.h>
    #include "gpio.h"
    unsigned char junk;

    int main(void)
    volatile unsigned int i;


    P4DIR |= 0x08; // Set P4.3 to output direction
    P4SEL |= BIT0+BIT4+BIT5; // P4.0,4,5 option select

    UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
    UCA1CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB; // 3-pin, 8-bit SPI master
    // Clock polarity high, MSB
    UCA1CTL1 |= UCSSEL_2; // SMCLK
    UCA1BR0 = 0x02; // /2
    UCA1BR1 = 0; //
    UCA1MCTL = 0; // No modulation
    UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
    UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt

    P4OUT &= ~0x08;

    UCA1TXBUF = 0x11;
    while (!(UCA1IFG&UCRXIFG));
    junk = UCA1RXBUF;

    // specify address to be CONFIG1
    UCA1TXBUF = 0x21;
    while (!(UCA1IFG&UCRXIFG));
    junk = UCA1RXBUF;

    // read  only 1 register
    UCA1TXBUF= 0x00;
    while (!(UCA1IFG&UCRXIFG));
    junk = UCA1RXBUF;

    // read register, 
    //UCA1TXBUF = b00000000;
    //while (!(UCA1IFG&UCRXIFG));
    //junk = UCA1RXBUF;

    /*while(1) // continuous loop
    P6OUT ^= BIT0; // XOR P1.0
    for(i=50000;i>0;i--); // Delay

    #pragma vector=USCI_A1_VECTOR
    __interrupt void USCI_A1_ISR(void)
    case 0:break; // Vector 0 - no interrupt
    case 2: // Vector 2 - RXIFG
    //while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
    case 4:break; // Vector 4 - TXIFG
    default: break;

  • David V said:
    From datasheet those pins have 3 functions? how to chose USCI_A1 UART mode?

    Take a look at the port pin schematics in the datasheet. It tells you which combination of direction and selection bits select which function.
    However, in case of the USCI, it is teh USCI configuration, not the port pin configuration, that defines the final usage. The port pin just has a 'from USCI' and 'to USCI' signal. It's meanign depends on the current configuration and maybe even the current state of teh USCI.

    In your case, there is a third level of configuration: the port mapping controller. If a port has a PM_xxx function, this means that the mapping of this module funciton to this pin can be changed by the port mapping controller. The shown one is only the default.
    It shoudl be noted, that (for the reasons given above), PM_UCA1TXD and PM_USCA1SIMO are actually the very same mapping option (same value)