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