This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR4133: SPI communication issue

Part Number: MSP430FR4133

Hello!

I am using msp430fr4133 launchpad as master mode & another msp430fr4133 controller board as slave. 

I simply send data from master to slave & monitor echoed data back.

I just want to display received data on LCD. But i didn't get any result.

Please provide any help. My code is here.

********************Master*******************


#include <msp430.h>
#include "global.h"

unsigned char RXData = 0;
unsigned char TXData;


int main(void)
{
WDTCTL = WDTPW | WDTHOLD;                                 // Stop watchdog timer

P5SEL0 |= BIT0 | BIT1 | BIT2 | BIT3;                               // set 4-SPI pin as second function

UCB0CTLW0 |= UCSWRST;                                              // **Put state machine in reset**
UCB0CTLW0 |= UCMST|UCSYNC|UCCKPL|UCMSB|UCMODE_1|UCSTEM;                          // 4-pin, 8-bit SPI master
                                                                                                                                                                       // Clock polarity high, MSB
UCB0CTLW0 |= UCSSEL__SMCLK;                                                                                                     // Select SMCLK
UCB0BR0 = 0x01;                                                              // /2,fBitClock = fBRCLK/(UCBRx+1).
UCB0BR1 = 0;
// UCA0MCTLW = 0;                                                          // No modulation
UCB0CTLW0 &= ~UCSWRST;                                            // **Initialize USCI state machine**
UCB0IE |= UCRXIE;                                                              // Enable USCI_A0 RX interrupt
TXData = 0x01;                                                                       // Holds TX data

PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings

while(1)
{
UCB0IE |= UCTXIE;                                                                 // Enable TX interrupt
__bis_SR_register(LPM0_bits | GIE);                                   // enable global interrupts, enter LPM0

__delay_cycles(2000);                                                               // Delay before next transmission
TXData++;                                                                                     // Increment transmit data

// __delay_cycles(20000);
}
}


#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCI_B0_ISR (void)
#else
#error Compiler not supported!
#endif

{
switch(__even_in_range(UCB0IV,USCI_SPI_UCTXIFG))
{
case USCI_NONE: break;                                // Vector 0 - no interrupt
case USCI_SPI_UCRXIFG:
RXData = UCB0RXBUF;
UCB0IFG &= ~UCRXIFG;
__bic_SR_register_on_exit(LPM0_bits); // Wake up to setup next TX


LCDDataOut(RXData,pos1);       //display receive data on LCD


break;
case USCI_SPI_UCTXIFG:
UCB0TXBUF = TXData;                                   // Transmit characters
UCB0IE &= ~UCTXIE;

break;
default: break;
}
}

***********************************Slave**********************************

#include <msp430.h>

int main(void)
{
WDTCTL = WDTPW|WDTHOLD;                                                       // Stop watchdog timer

P5SEL0 |= BIT0 | BIT1 | BIT2 | BIT3;                                                    // set 4-SPI pin as second function

UCB0CTLW0 |= UCSWRST;                                                                         // **Put state machine in reset**
UCB0CTLW0 |= UCSYNC|UCCKPL|UCMSB|UCMODE_1|UCSTEM;            // 4-pin, 8-bit SPI slave
// Clock polarity high, MSB
UCB0CTLW0 |= UCSSEL__SMCLK;                                                         // Select SMCLK
UCB0BR0 = 0x01;                                                                                         // /2,fBitClock = fBRCLK/(UCBRx+1).
UCB0BR1 = 0;
// UCB0MCTLW = 0; // No modulation
UCB0CTLW0 &= ~UCSWRST;                                                                  // **Initialize USCI state machine**
UCB0IE |= UCRXIE;                                                                                   // Enable USCI_A0 RX interrupt

PM5CTL0 &= ~LOCKLPM5;                                                                     // Disable the GPIO power-on default high-impedance mode
                                                                                                                       // to activate previously configured port settings

__bis_SR_register(LPM0_bits | GIE);                                                       // Enter LPM0, enable interrupts
}


#pragma vector=USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)

{
while (!(UCB0IFG&UCTXIFG));                                                                          // USCI_A0 TX buffer ready?
UCB0TXBUF = UCB0RXBUF;                                                                             // Echo received data
}

  • Hi Swati!

    Could you please narrow down your problem a bit? You say you are transmitting data from a master MSP430 to a slave MSP430 and that you want to show the data on a LCD. This is two ways of communication - which one does not work and what is the part of the code that does not behave as expected?

    Dennis
  • Hi Dennis,

    Thanks!!

    My problem is that I could not get any data on MISO pin of master msp430 launchpad board.

    Here my master board is msp430fr4133 launchpad & slave is another msp430fr4133 controller board of our design.

    I connected SCLk,MOSI,MISO,CS,VDD,GND pins to slave board. 

    Whether there is any issue in my code?

  • Does "could not get any data on MISO" mean that MISO is always high? Or always low? (Two separate symptoms.)

    How do you test this? Which side do you start first?

    As to the code, there are two things to note:
    1) By the time the slave gets to its ISR, the Tx/Rx at the master is already complete. Your "echo" mechanism will always be off by (at least) 1. This is pretty much unavoidable, but you can pre-load the slave's TXBUF with an eye-catcher (e.g. 0x5A meaning "busy" or something).
    2) In the master, the second time through the while() loop, when you set TXIE, GIE is already set. Thus, the Tx interrupt goes off immediately. Since your SPI clock is so fast, the Rx interrupt will go off while you're still processing the Tx interrupt, so it will be processed as well -- before main() goes to LPM0. When main() then goes to LPM0, there will be no interrupt sources left, so the master will stall forever. One way to avoid this is to precede the TXIE setting with __disable_interrupt().

    That said, I would expect the symptom to be (MISO): 8 bits of 0 (0x00 with SCLKs) 7 bits of 0 (0x01 with SCLKs), then no more SCLKs. And the symptom would vary depending on which side was started first. Thus the questions above.

**Attention** This is a public forum