1 | #include <msp430.h>
|
2 | #include "base.h"
|
3 |
|
4 | void SPI_init(void); // initialize the SPI communication
|
5 | void SPI_send(unsigned int data);
|
6 | void CS_Init(void); // clock system
|
7 |
|
8 | int main(void)
|
9 | {
|
10 | WDTCTL = WDTPW + WDTHOLD; // stop Watchdog timer
|
11 |
|
12 | CS_Init(); // set Timing
|
13 |
|
14 | SPI_init(); // Initialize SPI-Module UCA1
|
15 |
|
16 | while (1)
|
17 | {
|
18 | //_low_power_mode_3 (); // do nothing
|
19 | }
|
20 | }
|
21 |
|
22 |
|
23 | void SPI_init(void)
|
24 | {
|
25 | SETBIT(P2SEL1, BIT4); // Select secondary function of P2.4 (UCA1CLK)
|
26 | SETBIT(P2SEL1, BIT5); // Select secondary function of P2.5 (UCA1SIMO)
|
27 | SETBIT(P2SEL1, BIT6); // Select secondary function of P2.6 (UCA1SOMI)
|
28 |
|
29 | SETBIT(P2DIR, BIT3); // Declare P2.3 as Select Slave port
|
30 | SETBIT(P2OUT, BIT3); // Start with high on Select Slave P2.3
|
31 |
|
32 | SETBIT(UCA1CTLW0, UCSWRST); // Software reset enable. Have to be selected here
|
33 | SETBIT(UCA1CTLW0, UCCKPH); // select clock phase to rising clock phase
|
34 | SETBIT(UCA1CTLW0, UCMSB); // direction of shift register
|
35 | SETBIT(UCA1CTLW0, UCMST); // SPI master
|
36 | SETBIT(UCA1CTLW0, UCSYNC); // Synchronous mode enable
|
37 | SETBIT(UCA1CTLW0, UCSSEL_2); // SMCLK clock selected
|
38 | }
|
39 |
|
40 | void SPI_send(unsigned int data)
|
41 | {
|
42 | UCA1TXBUF = data; // send data
|
43 | }
|
44 |
|
45 | void CS_Init(void) //clock system
|
46 | {
|
47 | // set up Clock System
|
48 | CSCTL0 = CSKEY; // enable clock system
|
49 | CSCTL1 = DCOFSEL_3; // frequency = 8,0 MHz
|
50 | CSCTL2 = SELA__XT1CLK | SELS__DCOCLK | SELM__DCOCLK; // select clock sources
|
51 | CSCTL3 = DIVA__8 | DIVS__32 | DIVM__8; // set frequency divider
|
52 | CSCTL4 = XT2OFF | XTS | XT1DRIVE_0; // XT2 disabled, XT1: HF mode, low power, no bypass
|
53 | CSCTL0_H = 0; // disable clock system
|
54 | }
|