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.

SPI between a fpga and a microcontroller



I am using M430F2618T as a slave and Cyclone II fpga as a master in SPI data transfer. just for the purpose of testing, I want to transfer a square wave (MOSI signal) to microcontroller and get the same signal back as (MISO signal) at fpga. Here is the code for a microcontroller. Though I am able to get MOSI signal at microcontroller, I am not able to get MISO signal back at the fpga. Please suggest ay changes to be made in the microcontroller code.

#include <msp430x26x.h>

void main(void)
{
  WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer
  BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
  DCOCTL = CALDCO_1MHZ;


//                                            // it is not yet in SPI mode
  P3SEL |= 0x31;                            // P3.5,4,0 option select
  UCA0CTL1 = UCSWRST;                       // **Put state machine in reset**
  UCA0CTL0 |= UCSYNC+UCMSB;                 //3-pin, 8-bit SPI slave
  UCA0CTL0 &= ~UCMST;
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt


  while (1)
  {
    while (!(IFG2 & UCA0TXIFG));              // USCI_A0 TX buffer ready?
    UCA0TXBUF = UCA0RXBUF;

  }
}

 

  • varun dhage said:
    IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt

    This line enables receive interrupts, and your code doesn't seem to have an interrupt handler.  When the first character arrives at the MCU, the USCI generates an interrupt and the CPU tries to handle it, eventually running away and crashing.

    From what I can tell about your code, you don't need an interrupt when an RX character arrives.

    If you eliminate this line, it should work (aside from the first couple of characters the MCU sends, which won't be right).

    Jeff

  • I have a similar Problem. I am using two launchpads with MSP430G2553s as master and slave in 4-wire-mode. The slave receives the correct byte but i get no MISO signal back. The code for the slave is:

    #include <msp430.h>

    #define SIMO_BIT BIT7
    #define MISO_BIT BIT6
    #define SCLK_BIT BIT5
    #define STE_BIT BIT4

    void Init_SPI(void);

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

    Init_SPI();

    _BIS_SR(GIE);


    for(;;) {

    }

    }

    void Init_SPI(void)
    {
    // disable the module if enabled previously to make register configurations
    UCB0CTL1 = UCSWRST;

    // setup pin directions
    P1SEL |= SIMO_BIT + MISO_BIT + SCLK_BIT + STE_BIT;
    P1SEL |= SIMO_BIT + MISO_BIT + SCLK_BIT + STE_BIT;

    UCB0CTL0 |= UCCKPH + UCMSB + UCMODE_2 + UCSYNC; // MSB + Master + SPI-Mode

    // enable the module
    UCB0CTL1 &= ~UCSWRST;

    // Interrupt enable
    IE2 |= UCB0RXIE;
    }

    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCIB0RX_ISR (void)
    {

    while(!(IFG2&UCB0TXIFG)); 
    UCB0TXBUF= UCB0RXBUF; 

    }

**Attention** This is a public forum