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.

MSP430F5529: How to configure the 4 wire SPI Connection in salve MCU?

Part Number: MSP430F5529

Tool/software:

I have write the following code for SPI configuration but can't able to receive the data from the master

void spi_init(void)
{

P3SEL |= BIT0; // SOMI
P3SEL |= BIT1; // SIM0
P3SEL |= BIT2; // CLK
P2SEL |= BIT7; //CS

//P2DIR &= ~(BIT7) ; // Slave Select

UCB0CTL1 |= UCSWRST; // **Put state machine in reset**
UCB0CTL0 |= UCMODE_2+UCSYNC+UCCKPL+UCMSB; // 4-pin, 8-bit SPI Slave 0 enabled
// Clock polarity high, MSB
UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCB0IE |= UCRXIE; // Enable USCI_B0 RX interrupt

}

  • Hi, 

    Please refer to MSP430's SDK:

    C:\ti\msp\MSP430Ware_3_80_14_01\examples\devices\MSP430F5xx_6xx\MSP430F55xx_Code_Examples\C

    Here is the 4 wires SPI slave example code:

    6558.MSP430F55xx_usci_spi_standard_slave.c

    Regarads,

    Helic

  • thank you for the reply. the example is for 3 pin mode. I want to know the setup for 4 pin mode

  • Hi, 

    You can get the example usage guide from line 10 to line 21, P2.0 is for chip select.

    Do you mean that you need a SPI hardware CS pin?

    Not a software controlled P2.0 in demo code?

    Regards,

    Helic

  • Yes. I need the setup for SPI hardware CS pin P2.7 (UCB0STE)

  • Hi, 

    Please refer to User's Guide: https://www.ti.com/lit/ug/slau208q/slau208q.pdf

    40.3.4.1 4-Pin SPI Slave Mode

    And table [Table 40-1. UCxSTE Operation] in 40.3 eUSCI Operation – SPI Mode.

    Regards,

    Helic

  • I don't see anything obviously wrong with your code. Is your master also using (CPHA=1, CPOL=1)?

    How do you tell that you're not receiving data? (Breakpoint in ISR? Incorrect data bytes?)

    Data sheet (SLAS590N) Table 6-47 Note (3) mentions a possible conflict over P2.7 if you're also using UCA0 for SPI. I suspect you aren't, but I thought I should ask.

  • void spi_init(void)
    {
        P3SEL |= BIT0;      // MOSI
        P3SEL |= BIT1;      // MISO
        P3SEL |= BIT2;      // CLK
    
        P1DIR |= 0xff;      // set all to output direction  CS10, CS9, CS8, CS7, CS6, CS5, CS4, CS3
        P2DIR |= BIT1 + BIT0; //Set to Output Direction CS1, CS2;
    
        UCB0CTL1 |= UCSWRST;                      // **Put state machine in reset**
        UCB0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;    // 3-pin, 8-bit SPI master
                                                      // Clock polarity high, MSB
        UCB0CTL1 |= UCSSEL_2;                     // SMCLK 8MHz
        UCB0BR0 = 0x08;                           // /8 = 1Mhz
        UCB0BR1 = 0;                              //
        //UCB0MCTL = 0x00;                             // No modulation
        UCB0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    
    }
    
    void spi_init(void)
    {
        P3SEL |= BIT0;      // MOSI
        P3SEL |= BIT1;      // MISO
        P3SEL |= BIT2;      // CLK
    
        P1DIR |= 0xff;      // set all to output direction  CS10, CS9, CS8, CS7, CS6, CS5, CS4, CS3
        P2DIR |= BIT1 + BIT0; //Set to Output Direction CS1, CS2;
    
        UCB0CTL1 |= UCSWRST;                      // **Put state machine in reset**
        UCB0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;    // 3-pin, 8-bit SPI master
                                                      // Clock polarity high, MSB
        UCB0CTL1 |= UCSSEL_2;                     // SMCLK 8MHz
        UCB0BR0 = 0x08;                           // /8 = 1Mhz
        UCB0BR1 = 0;                              //
        //UCB0MCTL = 0x00;                             // No modulation
        UCB0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    
    }
    

    this is the configuration in master. In my program, I receive the data from master and then assign the values to the GPIO pins. So I check the GPIO pins, It's not giving the output. I  am using  UCB0 for the SPI configurations.

**Attention** This is a public forum