lunix 0 Posted March 9, 2012 Share Posted March 9, 2012 Hi all, I'm trying to do a loopback code on the MSP430G2553 chip. It's supposed to turn the red light off whenever the SPI UCA0 receives the character "A" transmitted from the master SPI UCB0. #include "msp430g2553.h" #include void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= BIT0; P1OUT |= BIT0; P1SEL = BIT1 + BIT2 + BIT4; P1SEL2 = BIT1 + BIT2 + BIT4; UCA0CTL1 = UCSWRST; // **Put state machine in reset** UCA0CTL0 |= UCCKPL + UCMSB + UCSYNC; // 3-pin, 8-bit SPI slave UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt // Slave setup done /////////////////////////////////////////////////////////////////////// P1SEL = BIT5 + BIT6 + BIT7; P1SEL2 = BIT5 + BIT6 + BIT7; UCB0CTL0 |= UCCKPL + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master UCB0CTL1 |= UCSSEL_2; // SMCLK UCB0BR0 |= 0x02; // /2 UCB0BR1 = 0; // //UCB0MCTL = 0; // No modulation UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCB0TXIE; // Enable USCI0 TX interrupt while(1) { __bis_SR_register(LPM0_bits + GIE); // Enter LPM4, enable interrupts } } interrupt(USCIAB0RX_VECTOR) USCI0RX_ISR(void) { if (UCA0RXBUF == 'A') { P1OUT &= ~BIT0; } } interrupt(USCIAB0TX_VECTOR) USCI0TX_ISR(void) { UCB0TXBUF = 'A'; // Transmit first character } I conneced pin 1.4 to pin 1.5, pin 1.2 to pin 1.7, pin 1.6 to pin 1.1. The jumper P1.6 on the launchpad board is disconnected with the LED. I seems like the code should work but it never does -- the red light stays on. Anyone would help me figure out why it's the case? Quote Link to post Share on other sites
lunix 0 Posted March 9, 2012 Author Share Posted March 9, 2012 Nevermind, got it to work, all I changed was to set up pin directions at the beginning. #include "msp430g2553.h" #include void transfer(char s) { while (!(IFG2 & UCB0TXIFG)); UCB0TXBUF = s; } void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= BIT0; P1OUT |= BIT0; P1SEL = BIT1 + BIT2 + BIT4 + BIT5 + BIT6 + BIT7; P1SEL2 = BIT1 + BIT2 + BIT4 + BIT5 + BIT6 + BIT7; UCA0CTL1 = UCSWRST; // **Put state machine in reset** UCA0CTL0 |= UCCKPL + UCMSB + UCSYNC; // 3-pin, 8-bit SPI slave UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** while(IFG2 & UCA0RXIFG); IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt // Slave setup done /////////////////////////////////////////////////////////////////////// __delay_cycles(60000); __delay_cycles(60000); __delay_cycles(60000); __delay_cycles(60000); UCB0CTL0 |= UCCKPL + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master UCB0CTL1 |= UCSSEL_2; // SMCLK UCB0BR0 |= 0x02; // /2 UCB0BR1 = 0; // //UCB0MCTL = 0; // No modulation UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCB0TXIE; // Enable USCI0 TX interrupt //transfer('A'); while(1) { __bis_SR_register(LPM4_bits + GIE); // Enter LPM4, enable interrupts } } // Echo character interrupt(USCIAB0RX_VECTOR) USCI0RX_ISR(void) { //while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready? if (UCA0RXBUF == 'A') { P1OUT &= ~BIT0; } } interrupt(USCIAB0TX_VECTOR) USCI0TX_ISR(void) { UCB0TXBUF = 'A'; // Transmit first character } Quote Link to post Share on other sites
fatihinanc 14 Posted March 9, 2012 Share Posted March 9, 2012 You can use debugger for like this things. Would you try, add to watch window the UCB0RXBUF ? This way, might be possible to find the problem as quickly. Quote Link to post Share on other sites
bluehash 1,581 Posted March 10, 2012 Share Posted March 10, 2012 Red Lobster reporting, I see. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.