Other Parts Discussed in Thread: MSP430G2553
I am trying to verify that my SPI has been configured properly and that my receive interrupts are working. For some reason I can't get it to receive the byte that I send. I have enabled the loopback mode but it doesn't seem like it is actually receiving anything that I send. I am using an MSP430g2553
Here is my code:
#include <msp430.h>
void initSPI_USCIA(void); //initializes SPI on USCIA0 for the sd card reader/writer
//void initI2C_USCIB(void); //initializes I2C on USCIB0 for the ADC from ASI
void initLED(void); //initializes led so we can toggle it
__interrupt void USCI0RX_ISR (void);
void main(void) {
WDTCTL = WDTPW | WDTHOLD; //Stop watchdog timer
initLED();
initSPI_USCIA();
while (!(IFG2 & UCA0TXIFG)){
//wait for ready to transmit
}
UCA0TXBUF = 0x11; //writes to spi data register
_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupts enabled
}
void initSPI_USCIA(void){
UCA0CTL1 |= UCSWRST; //set software reset to 1 so we can configure SPI
UCA0STAT |= UCLISTEN; //the launchpad listens to itself (use for testing)
UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC; //clkphase,clkpolarity,MSBfirst,8-bit,master mode, 3-pin, synchronous SPI
UCA0CTL1 |= UCSSEL_2; //choose SMCLK as our clock. SMCLK is 1.1 MHz. We divise it with the baud register
UCA0BR0 |= 0x02; //Baud rate is 1.1MHZ/(2+1) = 366 KHz
UCA0BR1 = 0; //upper byte of br register. set to zero
UCA0MCTL = 0; //No modulation
P1SEL |= (BIT1 | BIT2 | BIT4); //configures pins for three pin SPI. MISO P1.1, MOSI P1.2, CLK P1.4
P1SEL2 |= (BIT1 | BIT2 | BIT4); //configures pins for their peripheral setting
UCA0CTL1 &= !UCSWRST; //enables the SPI to work
IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
}
void initLED(void){
P1DIR |= BIT0; //sets red led to output and turns it on
P1OUT &= !BIT0; //turn red led off
}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR (void){
if(UCA0RXBUF == 0x11)
{
P1OUT = 0x01; //turn red led on
}
}