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.

[Help] MSP430G2553 communicate with DE2 FPGA board through GPIO

Prodigy 85 points

Replies: 15

Views: 4112

In my project, the DE2 has to transfer data to computer through MSP430G2553 (this is the strict requirement). Hence, I have 2 connection must be done:

1. The communication between MSP430 and computer: I already have used  UART module on MSP430 to realize this connection.

2. The communication between DE2 and MSP430 through GPIO : Currently, I do not know how to do this. 

Could you guys here help me how to implement the second connection?. ( I just take charge of the MSP430 coding, my partner will charge on DE2).

Thank you

15 Replies

  • Guru 46710 points

    tran vit
    2. The communication between DE2 and MSP430 through GPIO : Currently, I do not know how to do this. 

    Use SPI.

    tran vit
    I just take charge of the MSP430 coding, my partner will charge on DE2

    You have to use SPI peripheral as slave, your partner have to implement master SPI on DE2.

  • Since, I have only 5 weeks left to implement the communication between DE2 and MSP430. SPI is a way to do this but with the limit left time and knowledge in embedded system, I cannot use this protocol. Furthermore, MSP430 just needs to receive data from DE2 and transfer this data to computer through UART module. 

  • Guru 46710 points

    In reply to tran vit:

    tran vit
    Since, I have only 5 weeks left to implement the communication between DE2 and MSP430. SPI is a way to do this but with the limit left time and knowledge in embedded system, I cannot use this protocol. Furthermore, MSP430 just needs to receive data from DE2 and transfer this data to computer through UART module. 

    Look, SPI in it's simplest form is nothing more than 8 bits parallel-in serial-out register with clock output for master and opposite for slave. If you find this too complex to implement, then honestly - I have no idea what else to suggest you. For msp430 look for SPI master/slave examples in product page of your chip. FPGA shall have ready-to use SPI "library".

  • In reply to Ilmars:

    I suggest programming the MSP as master. usually, the MSP controls the FPGA, so it should be in charge of the transfer. Also, SPI master is much easier (by far not so time-critical) than SPI slave, when the high-level protocol is under software control. On the FPGA side, the SPI is more or less put in hardware completely, so implementing an SPI slave (especially with a ready-to-use library) doesn't expose any timing problems.

    And indeed, the transfer itself is more than simple. You may have a 'data vailable' signal from teh slave to the master, a 'start transfer' (chip select) signal form the master to the slave, and then you push out (and pull in) a bit at a time synchronized to the master-generated clock signal. It can be done by simple bit-banging or by using the hardware SPI of the MSP (USI, USCI or USART module, depending on used MSP)

    _____________________________________

    Time to say goodbye - I don't have the time anymore to read and answer forum posts. See my bio for details.

    Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
    I'm sorry that  I can no longer provide help  in the forum or by private conversation.

  • In reply to Jens-Michael Gross:

    Thanks for your answer. In this case, I have already used USCI for the UART communication between MSP430 and PC, so

    The first question: Can I use the USCI module for UART and SPI at the same time and how ? UART use UCA0 and SPI use UCA1?. For example: to implement the UART I used the code like below :

     c


    (http://forum.43oh.com)
    Hence, if I can use USCI for both SPI and UART, how can I get data from DE2 which used by SPI protocol and put this data to UCA0TXBUF buffer of UART ?. Do I need to write a buffer to store data get from DE2?
    The second question is that if i used the USI for SPI protocol (use slave mode). How can get data from shift register USISR and put this data to UCA0TXBUF in a interupt of USI because I know that USISR will shift data to output at PIN1.6 in serial.
     
    My questions may be so idiotic but I am very new with this board so I hope to receive your support


  • Guru 46710 points

    In reply to tran vit:

    tran vit
    I am very new with this board

    Then for you better to drop SPI idea, let your FPGA guy implement UART. Then you can make simple UART repeater out of msp430 or just solder msp430 out of board and rewire UART lines from FPGA to PC.

  • In reply to Ilmars:

    I must implement the SPI protocol like you guys here suggested because now it is compulsory. Hence, Could you instruct me more detail and answer my above questions? Thank you.

  • Guru 46710 points

    In reply to tran vit:

    You shall start reading SPI and UART example code for your chip.

  • In reply to Ilmars:

    As your suggestion, I have already finished the code and tested the communication between MSP and  DE2 this morning. The SPI protocol implemented on the DE2 seems to work properly when my partner simulated  the MOSI & MISO and SCLK correctly on the Oscilloscope. However, when DE2 connects to Lauchpad, the data (DE2 send character "A") cannot send to PC through MSP, displaying on the Hyper terminal program is just the strange characters (special characters). Hence, I will post my code here and hope that you guys here can indicate the problems that I made? Thank you very much.

    This code based on the examples from TI.

    #include <msp430G2553.h>
    #define RXD         BIT1 //Check your launchpad rev to make sure this is the case. Set jumpers to hardware uart.
    #define TXD         BIT2 // TXD with respect to what your sending to the computer. Sent data will appear on this line
    #define SCLK     BIT5
    #define SOMI     BIT6
    #define SIMO     BIT7
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
      BCSCTL1 = CALBC1_1MHZ;            // Set DCO to 1 MHz
        DCOCTL = CALDCO_1MHZ;
        // SPI SETUP AS SLAVE
                                                                          // If clock sig from mstr stays low,
        while (!(P1IN & BIT5));                                          // it is not yet in SPI mode
      P1SEL  |= SOMI + SIMO + SCLK + RXD + TXD;
      P1SEL2 |= SOMI + SIMO + SCLK + RXD + TXD;
      UCB0CTL1 = UCSWRST;                       // **Put state machine in reset**
      UCB0CTL0 |= UCCKPL + UCMSB + UCSYNC;      // 3-pin, 8-bit SPI slave
      UCB0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      IE2 |= UCB0RXIE;                          // Enable USCI0 RX interrupt
      //UART SETUP
        UCA0CTL1 |= UCSSEL_2;                     // SMCLK
        UCA0BR0 = 104;                            // 1MHz 9600
        UCA0BR1 = 0;                              // 1MHz 9600
        UCA0MCTL = UCBRS0;                        // Modulation UCBRSx = 1
        UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    //    IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt
      __bis_SR_register(LPM4_bits + GIE);       // Enter LPM4, enable interrupts
    }
    // Echo character
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCI0RX_ISR (void)
    {
      //while (!(IFG2 & UCA0TXIFG));              // USCI_A0 TX buffer ready?
    while ((UCA0STAT & UCBUSY));
      UCA0TXBUF = UCB0RXBUF;
    }
  • In reply to tran vit:

    Could you guys here help me to indicate the problem in my code?. 

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.