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.

CC430 SPI Communication

Hello,

I'm using a EM-CC430F6137-900 Board and I'm trying to get the SPI communication to work. I had a look at the example files for MSP430. This program works well.

May question now is: Is it possible to send and read data without the interrupt routine? 

For example:

#include <msp430.h> 

void initSPI()
{

        PMAPPWD = 0x02D52;                       // Get write-access to port mapping regs
        P2MAP2 = PM_UCB0SIMO;                    // Map UCA0SIMO output to P2.2
        P2MAP3 = PM_UCB0SOMI;                    // Map UCA0SOMI output to P2.3
        P2MAP4 = PM_UCB0CLK;                     // Map UCA0CLK output to P2.4
        PMAPPWD = 0;                             // Lock port mapping registers

	P2DIR |= BIT5 + BIT6;                    // Set chip selects for two spi components
	P2DIR |= BIT2 + BIT3 + BIT4;             // set output direction for clk and mosi
	P2SEL |= BIT2 + BIT3 + BIT4;             // switch to secondary function - spi in this case

	UCB0CTL1 |= UCSWRST;                     // **Put state machine in reset**
        UCB0CTL0 |= UCMST+UCSYNC+UCMSB+UCCKPH;   // 3-pin, 8-bit SPI master
	                                         // mode(0,0??), MSB
	UCB0CTL1 |= UCSSEL_2;                    // SMCLK
	UCB0BR0 = 0x02;                          // /2
	UCB0BR1 = 0;                             //
	UCB0CTL1 &= ~UCSWRST;                    // **Initialize USCI state machine**
	UCB0IE |= UCRXIE;                        // Enable USCI_B0 RX interrupt

	// Re-enable all interrupts
	__enable_interrupt();


}

char sendByteSPI (char send_data)
{
	while (!(UCB0IFG & UCTXIFG));             // USCI_B0 TX buffer ready?
	UCB0TXBUF = send_data;                    // Transmit first character

	while (!(UCB0IFG & UCRXIFG));             // USCI_B0 RX received complete character?
   return UCB0RXBUF;
}


int main(void) 
{
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    __disable_interrupt();
    
    initSPI();

    sendByteSPI(0x03);

}

For me it isn't clear, why this doesn't work. Is this the wrong way I think it works?

I hope you can help me.

Thanks, Chris

  • You're enabling the RX interrupt without an RX interrupt service routine. That will cause a hang or reset at the end of the first byte transfer. Leave the UCRXIE bit of UCB0IE clear.

    Other than that, can you give more detail on exactly how it "doesn't work". Is the 0x03 byte getting sent successfully? Are you seeing any signals on the clock and data pins?

  • Sorry, that my answer comes so late...

    I don't know why, but now it works. I didn't change anything in the example SPI routine. So it works now with the ISR function.

    Thanks for your answer. But even if I let the UCB0IE clear it won't work. On my clock line is nothing and so it is by the data pins. 

    I wil check it later on one more time, if I have another mistake in my Code. 

**Attention** This is a public forum