MSP430G2452 + SPI Communication

Discussion in 'Embedded Systems and Microcontrollers' started by pjk1939, Mar 2, 2012.

  1. pjk1939

    Thread Starter New Member

    Feb 29, 2012
    6
    0
    Hello,

    I recently bought myself one of TI's Launchpad baords that come with the MSP430 microcontroller. I was wondering if anyone could help explain how exactly the sample code is working.

    Code ( (Unknown Language)):
    1.  
    2.  //******************************************************************************
    3. //  MSP430G2xx2 Demo - SPI full-Duplex 3-wire Master
    4. //
    5. //  Description: SPI Master communicates full-duplex with SPI Slave using
    6. //  3-wire mode. The level on P1.4 is TX'ed and RX'ed to P1.0.
    7. //  Master will pulse slave reset for synch start.
    8. //  ACLK = n/a, MCLK = SMCLK = Default DCO
    9. //
    10. //                Slave                      Master
    11. //             MSP430G2xx2          MSP430G2xx2
    12. //             -----------------          -----------------
    13. //            |              XIN|-    /|\|              XIN|-
    14. //            |                 |      | |                 |
    15. //            |             XOUT|-     --|RST          XOUT|-
    16. //            |                 | /|\    |                 |
    17. //            |          RST/NMI|--+<----|P1.2             |
    18. //      LED <-|P1.0             |        |             P1.4|<-
    19. //          ->|P1.4             |        |             P1.0|-> LED
    20. //            |         SDI/P1.7|<-------|P1.6/SDO         |
    21. //            |         SDO/P1.6|------->|P1.7/SDI         |
    22. //            |        SCLK/P1.5|<-------|P1.5/SCLK        |
    23. //
    24. //  D. Dang
    25. //  Texas Instruments Inc.
    26. //  December 2010
    27. //  Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
    28. //******************************************************************************
    29.  
    30. #include <msp430g2452.h>
    31.  
    32.  
    33. void main(void)
    34. {
    35.   volatile unsigned int i;
    36.  
    37.   WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
    38.   P1OUT =  0x10;                        // P1.4 set, else reset
    39.   P1REN |= 0x10;                        // P1.4 pullup
    40.   P1DIR = 0x01;                         // P1.0 output, else input
    41.   USICTL0 |= USIPE7 +  USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI master
    42.   USICTL1 |= USIIE;                     // Counter interrupt, flag remains set
    43.   USICKCTL = USIDIV_4 + USISSEL_2;      // /16 SMCLK
    44.   USICTL0 &= ~USISWRST;                 // USI released for operation
    45.   USISRL = P1IN;                        // init-load data
    46.  
    47.   P1DIR |= 0x04;                        // Reset Slave
    48.   P1DIR &= ~0x04;
    49.   for (i = 0xFFF; i > 0; i--);          // Time for slave to ready
    50.   USICNT = 8;                           // init-load counter
    51.   _BIS_SR(LPM0_bits + GIE);             // Enter LPM0 w/ interrupt
    52. }
    53.  
    54. // USI interrupt service routine
    55. #pragma vector=USI_VECTOR
    56. __interrupt void universal_serial_interface(void)
    57. {
    58.   if (0x10 & USISRL)
    59.     P1OUT |= 0x01;
    60.   else
    61.     P1OUT &= ~0x01;
    62.   USISRL = P1IN;
    63.   USICNT = 8;                           // re-load counter
    64. }
    65.  
    My main question is when it is resetting the slave to synchronize the clock. Do I need to actually connect the slave to Pin 1.4?

    Thanks in advance.
     
Loading...