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.

MSP430G2553: SPI Receive

Part Number: MSP430G2553
Other Parts Discussed in Thread: MSP430G2533

Tool/software:

Hello, I'm trying to send a hex value from on MSP430G2533 (let's call is MSP430 transmitter) to another MSP430G2533 (let's call MSP430 receiver) over SPI.

I'm able to send and view the hex value on the TX buffer on MSP430 transmitter in the debugger view. However, my MSP430 receiver is unable to obtain the buffer. Here is my code


Spi receive code:

#include <msp430.h>

void setupSPI_Slave() {
    // Set UCSWRST (USCI Software Reset)
    UCB0CTL1 = UCSWRST;
    // Set USCI_B0 to slave mode, 3-pin SPI, synchronous mode
    UCB0CTL0 = UCSYNC + UCCKPL + UCMSB;
    // Clear UCSWRST to release USCI_B0 for operation
    UCB0CTL1 &= ~UCSWRST;
    // Enable USCI_B0 RX interrupt
    IE2 |= UCB0RXIE;
}

int main(void) {
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    P1SEL |= BIT5 + BIT6 + BIT7; // Set P1.5, P1.6, P1.7 as SPI pins
    P1SEL2 |= BIT5 + BIT6 + BIT7;

    setupSPI_Slave();

    __bis_SR_register(GIE); // Enable global interrupts

    while (1) {
        __bis_SR_register(LPM0_bits + GIE);
    }
}

// USCI_B0 Data ISR
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void) {
    if (IFG2 & UCB0RXIFG) {
        unsigned char receivedData = UCB0RXBUF; // Read received data
        // Do something with the received data
        __bic_SR_register_on_exit(LPM0_bits); // Exit low-power mode
    }
}

SPI Transmit code:

#include <msp430.h>

void setupSPI_Master() {
    // Set UCSWRST (USCI Software Reset)
    UCB0CTL1 = UCSWRST;
    // Set USCI_B0 to master mode, 3-pin SPI, synchronous mode
    UCB0CTL0 = UCMST + UCSYNC + UCCKPL + UCMSB;
    // SMCLK as clock source
    UCB0CTL1 |= UCSSEL_2;
    // Set baud rate (UCB0BR0 and UCB0BR1)
    UCB0BR0 = 0x02;
    UCB0BR1 = 0;
    // Clear UCSWRST to release USCI_B0 for operation
    UCB0CTL1 &= ~UCSWRST;
    // Enable USCI_B0 RX interrupt
    IE2 |= UCB0RXIE;
}

void sendSPI_Master(unsigned char data) {
    while (!(IFG2 & UCB0TXIFG)); // Wait for TX buffer to be ready
    UCB0TXBUF = data;            // Send data
}

int main(void) {
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    P1SEL |= BIT5 + BIT6 + BIT7; // Set P1.5, P1.6, P1.7 as SPI pins
    P1SEL2 |= BIT5 + BIT6 + BIT7;
    P1DIR |= BIT4; // Set P1.4 as output (CS pin)
    P1OUT |= BIT4; // Set P1.4 high (CS idle high)

    setupSPI_Master();

    while (1) {
        P1OUT &= ~BIT4; // Pull CS low to start communication
        sendSPI_Master(0xFF);
        P1OUT |= BIT4; // Set CS high to end communication
        __delay_cycles(1000); // Delay between transmissions
    }
}

  • Hi,

    Have you ever captured the waveform to see transmit data successfully?

    Zoey

  • Just looking at the comments I see a disconnect. On the transmit side you assert a CS signal but the receive side is set to 3 pin mode so is always enabled. It needs to be in the 4 pin mode for the STE input to do something with that CS signal. Oh, a test value that has both ones and zeros would be way better than 0xff.

    Another thing to check is the connection between the two devices. Make sure that the receiving pin (SIMO) really is connected to the transmit pin. (also SIMO)

**Attention** This is a public forum