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 MSP430 example.

Other Parts Discussed in Thread: MSP430G2221

Hello..

I try to understand the SPI communication betwen 2 launchpad.

I saw the example msp430g2x21_usi_02.c and msp430g2x21_usi_03.c and I don't understand.

This 2 code work together?

Is possible to do it with 2 launchpad?

Could you example for me who to send a bit to other launchpad?

Could you example to me what is RST/NMI and how I will use this if this is the same pin that is in S1 (reset) in launchpad.

 


  • Raul Rosetto Mu��oz said:
    This 2 code work together?

    I don't know the code, but I dimly remember there are two code examples which work as master  and slave code for a pair.

    The code you posted is for the slave. (see the first line)

    Raul Rosetto Mu��oz said:
    Is possible to do it with 2 launchpad?

    I don't think there is a reason why there should be demo code for a G device wihtout being emeant for use with the LaunchPad. SInce the G devices were introduced with the LaunchPad and seldom bought without one yet. But who knows :)

    Raul Rosetto Mu��oz said:
    Could you example for me who to send a bit to other launchpad?

    teh two lines USISRL (USI Shift Register Lowbyte) 0 P1IN writes teh content of P1IN (including the input bit on P1.4) into the output shift register, and USICNT (USI CouNT) = 8 tells the usi that there are 8 bits to send.

    Since this is the slave code, teh 8 bits are sent to the master when the master sends a clock signal.

    When 8 bits have been sent, 8 bits have been received too, so an interrupt is generated and the ISR will set P1.0 based on teh BIT4 of the received byte (the input pin of the master). And I guess the master does the same. Jus tthe initialization of the USI is different (master mode, including baudrate setting).

    Raul Rosetto Mu��oz said:
    Could you example to me what is RST/NMI and how I will use this if this is the same pin that is in S1 (reset) in launchpad.

    On all MSPs, teh reset pin can be configured to act as an NMI (Non Maskable Interrupt) signal pin rather than reset. If it is configured, the reset pin ceases working as reset pin.

    In this case, however, it is jsut used as reset poin. That means, the master can reset the slave using its P1.2 output. This is necessary, as the SPI protocol does not know any byte synchronisation 8such as the start/stopbits in UART transfers). So the master has to signal the slave that NOW the next clock signal is meant to be the beginning of a new data byte. In this case it is done brutally by resetting the slave.

  • Raul Rosetto Mu��oz said:
    This 2 code work together?

    I don't know the code, but I dimly remember there are two code examples which work as master  and slave code for a pair.

    The code you posted is for the slave. (see the first line)

    Raul Rosetto Mu��oz said:
    Is possible to do it with 2 launchpad?

    I don't think there is a reason why there should be demo code for a G device wihtout being emeant for use with the LaunchPad. SInce the G devices were introduced with the LaunchPad and seldom bought without one yet. But who knows :)

    Raul Rosetto Mu��oz said:
    Could you example for me who to send a bit to other launchpad?

    teh two lines USISRL (USI Shift Register Lowbyte) 0 P1IN writes teh content of P1IN (including the input bit on P1.4) into the output shift register, and USICNT (USI CouNT) = 8 tells the usi that there are 8 bits to send.

    Since this is the slave code, teh 8 bits are sent to the master when the master sends a clock signal.

    When 8 bits have been sent, 8 bits have been received too, so an interrupt is generated and the ISR will set P1.0 based on teh BIT4 of the received byte (the input pin of the master). And I guess the master does the same. Jus tthe initialization of the USI is different (master mode, including baudrate setting).

    Raul Rosetto Mu��oz said:
    Could you example to me what is RST/NMI and how I will use this if this is the same pin that is in S1 (reset) in launchpad.

    On all MSPs, teh reset pin can be configured to act as an NMI (Non Maskable Interrupt) signal pin rather than reset. If it is configured, the reset pin ceases working as reset pin.

    In this case, however, it is jsut used as reset poin. That means, the master can reset the slave using its P1.2 output. This is necessary, as the SPI protocol does not know any byte synchronisation 8such as the start/stopbits in UART transfers). So the master has to signal the slave that NOW the next clock signal is meant to be the beginning of a new data byte. In this case it is done brutally by resetting the slave.

  • Do you know where I can find a SPI that use 16-bits?

     

    thanks for all

  • SPI effectively is a bitstream. So there is no difference in sending two 8 bit values or one 16 bit value. The USCI is not suited for transfers with transfer sized that are not a multiple of 8, but that is a very uncommon case (all SPI slaves I know of are padding to a multiple of 8 bits).

    In fact, with the double-buffering (you can write the next byte to TXBUF while the last is being transmitted), you cannot tell a difference between two 8 bit transfers or one 16 bit transfer when scoping the line.

    The only thing to do is that if the transfers are meant to be 16 bit that you need to always send two bytes (and two dummy bytes to receive a 16 bit value) and combine the received two bytes to a single 16 bit value. That´s basic C.

    However, there IS are MSPs with (up to) 16 bit SPI. The USI module has an SPI that is not double buffered but allows any number of bits from 1 to 16. However, you have to wait for one word to be sent before you can configur ethe next transfer. Which makes programming a slave a really time-critical thing and also prevents maximum throughput (the transfer inherently stops after one transfer and before starting the next, since you have to configure the USI between single transfers).

  •  

    Hello....

    I try to finish the communication betwen 2 MSP430 but I didn't understandy how to get the start bit...

    In this code example I stay all the time in __interrupt void universal_serial_interface(void) and   if (i == 0xBB) I get the correct data...

    I know that I'm in a loop inside the serial interrupt because J is every time diferrent!

    Plz Some one could help me to understand how to create a interrupt to se the start bit!

    (the master code send 0xBB)

     

    // USI interrupt service routine

     

    #pragma vector=USI_VECTOR

    __interrupt void universal_serial_interface(void)

    {

      i = USISRL & 0xFF;

      j++;

      if (i == 0xBB)

      {

          USISRL = 0x09;

          USICNT = 8;                           // re-load counter

      }

    }

     

    #include <msp430g2221.h>

    char i = 0;

    char j = 0;

    void main(void)

    {

      WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer

      P1OUT =  0x10;                        // P1.4 set, else reset

      P1REN |= 0x10;                        // P1.4 pullup

      P1DIR = 0x01;                         // P1.0 output, else input

      USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIOE; // Port, SPI slave

      USICTL1 |= USIIE;                     // Counter interrupt, flag remains set

      USICTL0 &= ~USISWRST;                 // USI released for operation

      USISRL = P1IN;                        // init-load data

    //  USISRL = 0x0C;                        // init-load data  

    //  USICNT = 8;                           // init-load counter

      _BIS_SR(LPM0_bits + GIE);             // Enter LPM0 w/ interrupt

    }


    // USI interrupt service routine

    #pragma vector=USI_VECTOR

    __interrupt void universal_serial_interface(void)

    {

      i = USISRL & 0xFF;

      if (i == 0x0E)

      {

          USISRL = 0x09;

          USICNT = 8;                           // re-load counter

      }

    }

     

     

  • Raul Rosetto Mu��oz said:
    I didn't understandy how to get the start bit.

    This thread is about SPI, and SPI does not have a 'start bit'.
    So what you are talking about?

    The USI module does not have UART capabilities (the only thing that has a 'start bit'). And the 'start condition' is part of the I2C protocol, supported by the USI, but not related to SPI too.

    So either you're in the wrong thread or you have completely mixed-up some things.

  • Hi,

    I am working exactly on the same thing :)

    Do you have any working master-slave code yet?

    Thank you!

**Attention** This is a public forum