Part Number:MSP430G2553
Tool/software: Code Composer Studio
Hello! I am new to working with SPI communication/the MSP430G2xx3 and am simply trying to read pH sensor values from the LMP91200 evaluation board. However, while I am trying to receive the three bytes in the interrupt section, UCB0RXBUF always has value 0. Would appreciate guidance on how to resolve this issue!
//****************************************************************************** // MSP430G2xx3 // ----------------- // /|\| XIN|- MSP430 3.3V (J1.13 +3.3V DUT) // | | | MSP430 GND (J1.10) // | XOUT|- // | | // | | // | | // | P1.6|<- Data In (UCB0SOMI) (J1.27 SMSO B) // | | // (J1.23)ADC SEL <-|P1.3 P1.5|-> Serial Clock Out (UCB0CLK) (J1.25 SCK_B) // //****************************************************************************** #include <msp430.h> #define DUMMY 0xFF unsigned int RxByteCtr = 2; unsigned int ReceiveIndex = 0; unsigned char RxWord; unsigned char ReceiveBuffer[2] = {0}; //[0] MSB, [1] LSB unsigned char MST_Data; int main(void) { volatile unsigned int i; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1OUT = 0x00; // P1 setup for LED & reset output P1DIR |= BIT0 + BIT3; // P1SEL = BIT5 + BIT6 + BIT7; P1SEL2 = BIT5 + BIT6 + BIT7; UCB0CTL0 |= UCCKPL + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master UCB0CTL1 |= UCSSEL_2; // SMCLK UCB0BR0 |= 0x01; // /1 = 1MHz, 4.5 max, 0.9 min UCB0BR1 = 0; // UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCB0RXIE; // Enable USCI0 RX interrupt P1OUT |= BIT3; // deselect ADC __delay_cycles(50); P1OUT &= ~BIT3; // select/enable ADC __delay_cycles(50); UCB0TXBUF = DUMMY; // transmit first byte __bis_SR_register(LPM0_bits + GIE); // CPU off, enable interrupts } // Test for valid RX and TX character #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCIAB0RX_VECTOR __interrupt void USCIB0RX_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(USCIAB0RX_VECTOR))) USCIB0RX_ISR (void) #else #error Compiler not supported! #endif { volatile unsigned int i; while (!(IFG2 & UCB0RXIFG)); // USCI_B0 RX buffer ready? RxWord = UCB0RXBUF; if (RxByteCtr > 0) { ReceiveBuffer[ReceiveIndex] = RxWord; ReceiveIndex++; RxByteCtr--; while (!(IFG2 & UCB0TXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = DUMMY; // transmit the second & third bytes } if (RxByteCtr == 0) { RxByteCtr = 2; ReceiveIndex = 0; P1OUT |= BIT3; // deselect ADC __delay_cycles(50); P1OUT &= ~BIT3; // select ADC } }