1 | *******************************************************************************
|
2 | *
|
3 | * MSP430 CODE EXAMPLE DISCLAIMER
|
4 | *
|
5 | * MSP430 code examples are self-contained low-level programs that typically
|
6 | * demonstrate a single peripheral function or device feature in a highly
|
7 | * concise manner. For this the code may rely on the device's power-on default
|
8 | * register values and settings such as the clock configuration and care must
|
9 | * be taken when combining code from several examples to avoid potential side
|
10 | * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
|
11 | * for an API functional library-approach to peripheral configuration.
|
12 | *
|
13 | * --/COPYRIGHT--*/
|
14 | //******************************************************************************
|
15 | // MSP430F20x2/3 Demo - SPI full-Duplex 3-wire Master
|
16 | //
|
17 | // Description: SPI Master communicates full-duplex with SPI Slave using
|
18 | // 3-wire mode. The level on P1.4 is TX'ed and RX'ed to P1.0.
|
19 | // Master will pulse slave reset for synch start.
|
20 | // ACLK = n/a, MCLK = SMCLK = Default DCO
|
21 | //
|
22 | // Slave Master
|
23 | // MSP430F20x2/3 MSP430F20x2/3
|
24 | // ----------------- -----------------
|
25 | // | XIN|- /|\| XIN|-
|
26 | // | | | | |
|
27 | // | XOUT|- --|RST XOUT|-
|
28 | // | | /|\ | |
|
29 | // | RST/NMI|--+<----|P1.2 |
|
30 | // LED <-|P1.0 | | P1.4|<-
|
31 | // ->|P1.4 | | P1.0|-> LED
|
32 | // | SDI/P1.7|<-------|P1.6/SDO |
|
33 | // | SDO/P1.6|------->|P1.7/SDI |
|
34 | // | SCLK/P1.5|<-------|P1.5/SCLK |
|
35 | //
|
36 | // M. Buccini / L. Westlund
|
37 | // Texas Instruments Inc.
|
38 | // October 2005
|
39 | // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.40A
|
40 | //******************************************************************************
|
41 |
|
42 | #include <msp430.h>
|
43 |
|
44 | int main(void)
|
45 | {
|
46 | volatile unsigned int i;
|
47 |
|
48 | WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
|
49 | P1OUT = 0x10; // P1.4 set, else reset
|
50 | P1REN |= 0x10; // P1.4 pullup
|
51 | P1DIR = 0x01; // P1.0 output, else input
|
52 | USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI master
|
53 | USICTL1 |= USIIE; // Counter interrupt, flag remains set
|
54 | USICKCTL = USIDIV_4 + USISSEL_2; // /16 SMCLK
|
55 | USICTL0 &= ~USISWRST; // USI released for operation
|
56 | USISRL = P1IN; // init-load data
|
57 |
|
58 | P1DIR |= 0x04; // Reset Slave
|
59 | P1DIR &= ~0x04;
|
60 | for (i = 0xFFF; i > 0; i--); // Time for slave to ready
|
61 | USICNT = 8; // init-load counter
|
62 | __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
|
63 | }
|
64 |
|
65 | // USI interrupt service routine
|
66 | #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
|
67 | #pragma vector=USI_VECTOR
|
68 | __interrupt void universal_serial_interface(void)
|
69 | #elif defined(__GNUC__)
|
70 | void __attribute__ ((interrupt(USI_VECTOR))) universal_serial_interface (void)
|
71 | #else
|
72 | #error Compiler not supported!
|
73 | #endif
|
74 | {
|
75 | if (0x10 & USISRL)
|
76 | P1OUT |= 0x01;
|
77 | else
|
78 | P1OUT &= ~0x01;
|
79 | USISRL = P1IN;
|
80 | USICNT = 8; // re-load counter
|
81 | }
|