Other Parts Discussed in Thread: MSP430FR6047
I'm trying to connect an EVM430-FR6047 to an Adafruit RFM9x using the SPI interface, but I'm not finding any libraries/code samples. I've been able to use Arduino libraries from Adafruit/RadioHead (https://github.com/adafruit/RadioHead) . Please pass along any information you may have.
In the meantime, I'm trying to make sure that I'm understanding the SPI interface on the EVM430-FR6047 by using one of the code samples from TI: msp430fr60x7_euscia0_spi_09. For testing purposes, I have two EVM430-FR6047s connected together using a three-wire SPI connection:
Board #1: Board #2:
P7.0 SPI_MOSI --> P7.1 SPI_MISO
P7.1 SPI_MISO --> P7.0 SPI_MOSI
P7.2 SPI_SCLK --> P7.1 SPI_SCLK
I'm definitely not an expert on this stuff, but my understanding is that I should be able to send data from one board to the other and use the debugger to see the result. The program compiles and runs and the ISR triggers for both the TX and RX signals, but the data received (RXData) is always 0.
Here's the code:
#include <msp430fr6047.h>
volatile unsigned char RXData = 0;
volatile unsigned char TXData;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Configure GPIO
P7SEL1 &= ~BIT0 | ~BIT2 | ~BIT3; // USCI_A1 SCLK, MOSI, MISO pins
P7SEL0 |= BIT0 | BIT2 | BIT3;
PJSEL0 |= BIT4 | BIT5; // For XT1
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
// XT1 Setup
CSCTL0_H = CSKEY_H; // Unlock CS registers
CSCTL1 = DCOFSEL_0; // Set DCO to 1MHz
CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // set all dividers
CSCTL4 &= ~LFXTOFF;
do
{
CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag
SFRIFG1 &= ~OFIFG;
} while (SFRIFG1 & OFIFG); // Test oscillator fault flag
CSCTL0_H = 0; // Lock CS registers
// Configure USCI_A0 for SPI operation
UCA1CTLW0 = UCSWRST; // **Put state machine in reset**
UCA1CTLW0 |= UCMST | UCSYNC | UCCKPL | UCMSB; // 3-pin, 8-bit SPI master
// Clock polarity high, MSB
UCA1CTLW0 |= UCSSEL__ACLK; // ACLK
UCA1BRW = 0x02; // /2
UCA1MCTLW = 0; // No modulation
UCA1CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt
TXData = 0x1; // Holds TX data
while(1)
{
UCA1IE |= UCTXIE;
__bis_SR_register(LPM0_bits | GIE); // CPU off, enable interrupts
__delay_cycles(2000); // Delay before next transmission
TXData++; // Increment transmit data
}
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=EUSCI_A1_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(EUSCI_A1_VECTOR))) USCI_A1_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCA1IV, USCI_SPI_UCTXIFG))
{
case USCI_NONE: break;
case USCI_SPI_UCRXIFG:
RXData = UCA1RXBUF;
UCA1IFG &= ~UCRXIFG;
__bic_SR_register_on_exit(LPM0_bits); // Wake up to setup next TX
break;
case USCI_SPI_UCTXIFG:
UCA1TXBUF = TXData; // Transmit characters
UCA1IE &= ~UCTXIE;
break;
default: break;
}
}
I made a few changes from the original version of this program because it seemed to be written for some other EVM board. The original code used P1.0, P1.2, and P1.3 for SPI_SCLK, SPI_MOSI, SPI_MISO (in that order). The EVM430-FR6047 user guide shows P7.2, P7.0, and P7.1 for those connections. The other modification was to replace #include <msp430.h> with #include <msp430fr6047.h>.
I actually tried several combinations:
- Using the original code for P1.0, P1.2, and P1.3
- Using the original #include <msp430.h>
A similar test using the UART interface worked perfectly with the sample msp430fr60x7_euscia0_uart_03.c, so I'm not understanding why the SPI interface isn't working. Here's the physical setup:
Thanks!