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

Other Parts Discussed in Thread: MSP430G2553

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

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

    Use SPI.

    tran vit said:
    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. 

  • tran vit said:
    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".

  • 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)

  • 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


  • tran vit said:
    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.

  • 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.

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

  • 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;
    }
  • Could you guys here help me to indicate the problem in my code?. 

  • Special Characters on a terminal program may have several reasons. One of them is a physically wrong connection, but since you're likely using the LaunchPads application UART, this should be fine.

    The other reson is a wrong baudrate. Your code looks fine, but maybe your configuraiton of the clock fails. Maybe you have accidentally erased the timing constants and therefore your MSP isn't running at 1MHz as you expect.
    The typical demo code has a check before setting CALDCO_1MHZ that enters an endless loop if the constants happen to be 0xff (= erased).

    Another problem of your code is that the MSP may receive data from SPI much, much faster than it can send it through UART. But this would lead to missing´characters, not to wrong ones.

  • Thank for your reply,

    With  first two problems, I can figure out how to fix it. 

    In the third problem: I understand the problem you mentioned and currently DE2 is the master and provide clock signal of 1MHz for slave MSP. Hence, to overcome the third  problem, can I increase cycle of clock source (decrease the frequency) from DE2?. For example, DE2 will provide clock of 500 Khz for slave MSP?

    From your reply, I will test it tomorrow with my partner and hope that i work out.

  • tran vit said:
    For example, DE2 will provide clock of 500 Khz for slave MSP?

    Both, SPI and I2C are synchronous communication protocols. That means, the master doesn't only send data, it also provides the clock. For SPI, it can go down to 0Hz, on I2C, the 'normal' clock range is defined as 10kHz to 100kHz (400kHz on second standard revision and 1MHz on third). Some I2C slaves will imeout, but the I2C standard doesn't define a timeout. So basically, if the slave doesn't timeout, the clock can be down to 0Hz as well.

    In both protocols, clock speed may even change mid-byte, so clock jitter isn't a problem too.

  • Because you said that, MSP may receive data from SPI much faster than it can send it through UART, so how to send all 8 bit data on "receive buffer" of SPI to "transmit buffer" of UART before the next character come to " receive buffer" of SPI and create an interrupt? If i can do that, definitely I cannot lose a certain character. For example, after the command UCA0TXBUF = UCB0RXBUF, can I create a delay so that the data can be transferred completely before a new character come to the UCB0RxBUF of SPI.

  • tran vit said:
    w to send all 8 bit data on "receive buffer" of SPI to "transmit buffer" of UART before the next character come to " receive buffer" of SPI and create an interrupt?

    If you get 100kB per second through SPI and can only send 1kB per second through UART (9600Bd = 960byte/s), this simply won't work.

    However, if you only get short bursts of, say, 8 bytes per SPI and then you won't get anything for a longer time, you may simply collect the incoming SPi data in a ram array and send it through UART with a different speed. Depending on the effort you put into this buffer, you may eihter wait until teh SPI transfer is complete and then send the collected data through UART in a block, or you set up a ringbuffer, where the UART sends as soon as a byte is put into the ringbuffer, and stops when there's nothing in the ringbuffer, waiting for the next data arriving.

    Both methods decouple the receiving side from the sending side. The firs tis quite simple (fill an array, then send the array) but requires the number of incoming bytes per packet to be known. The second method works for any packet size up to the buffer size, but requires much more control logic in the code. It is, however, a rather universal approach that can be (re)used for any decoupled background receiving and sending purpose.

    tran vit said:
    For example, after the command UCA0TXBUF = UCB0RXBUF, can I create a delay so that the data can be transferred completely before a new character come to the UCB0RxBUF of SPI.

    This won't work. As SPI slave, you don't have any control over incoming SPI data. When it comes, it comes. If the CPU isn't ready to pick it from RXBUF, the next incoming byte will overwrite RXBUF with the latest one, and the previous is lost. Nothing you can do. That's the drawback of being a slave: be ready when the master calls or be punished.

**Attention** This is a public forum