Other Parts Discussed in Thread: MSP-EXP430FR5739
I am trying to use the MSP-EXP430FR5739 to talk to a wireless module and when I set it up and attempt to communicate with it, it returns an invalid response. However, if I step through the code with the debugger it receives the expected response.
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P1DIR |= (BIT0 + BIT4 +BIT3);
P1OUT &= ~BIT0;
P1OUT |= (BIT4 + BIT3);
P1SEL1 |= BIT5;//+BIT4;
P2SEL1 |= BIT0 + BIT1;
UCA0CTLW0 |= UCSWRST; // **Put state machine in reset**
UCA0CTLW0 |= UCMST|UCMSB|UCSYNC;//|UCMODE1|UCSTEM; // 3-pin, 8-bit SPI master
UCA0CTLW0 |= UCCKPH; // Clock polarity low, MSB
UCA0CTLW0 |= UCSSEL_2; // ACLK
UCA0BR0 = 0x08; // /2
UCA0BR1 = 0; //
// UCA0STATW |= UCLISTEN;
UCA0MCTLW = 0; // No modulation
UCA0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt
P1OUT &= ~BIT3;
P1OUT |= BIT3;
__delay_cycles(100);
// radio_init();
// unsigned char address[] ={0x22};
while(1)
{
RXData = spi_read(0x22);
_delay_ms(100);
// RXData = 0;
}
}
unsigned char spi_read(unsigned char address)
{
unsigned char data = 0;
P1OUT &= ~BIT4;
data = UCA0RXBUF;
while(UCA0STATW&UCBUSY == UCBUSY);
UCA0TXBUF = address;
// __delay_cycles(10);
data = UCA0RXBUF;
// while(UCA0STATW&UCBUSY == UCBUSY);
_delay_ms(10);
UCA0TXBUF = 0xff;
data = UCA0RXBUF;
P1OUT |= BIT4;
return data;
}
I do not understand why it will get a valid response when stepping through and not when just executing the code.
Thanks for your help