1 | WDTCTL = WDTPW | WDTHOLD;
|
2 | //Set DCO frequency to max DCO setting
|
3 | CS_setDCOFreq(CS_DCORSEL_0,CS_DCOFSEL_3);
|
4 | //Select DCO as the clock source for SMCLK with no frequency divider
|
5 | CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
|
6 | /*
|
7 | * Select CS
|
8 | * Set Pin 0 as output
|
9 | */
|
10 | GPIO_setAsOutputPin(
|
11 | GPIO_PORT_P5,
|
12 | GPIO_PIN4
|
13 | );
|
14 |
|
15 | /*
|
16 | * Select Port 5
|
17 | * Set Pin 0 to output Low.
|
18 | */
|
19 | GPIO_setOutputLowOnPin(
|
20 | GPIO_PORT_P5,
|
21 | GPIO_PIN4
|
22 | );
|
23 |
|
24 | //Configure Pins for UCB0CLK
|
25 | GPIO_setAsPeripheralModuleFunctionInputPin(
|
26 | GPIO_PORT_P5,
|
27 | GPIO_PIN2,
|
28 | GPIO_SECONDARY_MODULE_FUNCTION
|
29 | );
|
30 |
|
31 | //Configure Pins for UCB0TXD/UCB0SIMO, UCB0RXD/UCB0SOMI
|
32 | GPIO_setAsPeripheralModuleFunctionInputPin(
|
33 | GPIO_PORT_P5,
|
34 | GPIO_PIN0 + GPIO_PIN1,
|
35 | GPIO_SECONDARY_MODULE_FUNCTION
|
36 | );
|
37 |
|
38 | /*
|
39 | * Disable the GPIO power-on default high-impedance mode to activate
|
40 | * previously configured port settings
|
41 | */
|
42 | PMM_unlockLPM5();
|
43 |
|
44 | //Initialize Master
|
45 | EUSCI_B_SPI_initMasterParam param = {0};
|
46 | param.selectClockSource = EUSCI_B_SPI_CLOCKSOURCE_SMCLK;
|
47 | param.clockSourceFrequency = CS_getSMCLK();
|
48 | param.desiredSpiClock = 500000;
|
49 | param.msbFirst = EUSCI_B_SPI_MSB_FIRST;
|
50 | param.clockPhase = EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT;
|
51 |
|
52 | param.clockPolarity = EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH;
|
53 | param.spiMode = EUSCI_B_SPI_3PIN;
|
54 | EUSCI_B_SPI_initMaster(EUSCI_B1_BASE, ¶m);
|
55 |
|
56 | //Enable SPI module
|
57 | EUSCI_B_SPI_enable(EUSCI_B1_BASE);
|
58 |
|
59 | //Clear RXIFG interrupt flag
|
60 | EUSCI_B_SPI_clearInterrupt(EUSCI_B1_BASE, EUSCI_B_SPI_RECEIVE_INTERRUPT);
|
61 |
|
62 | // Enable USCI_B0 RX interrupt
|
63 | EUSCI_B_SPI_enableInterrupt(EUSCI_B1_BASE,
|
64 | EUSCI_B_SPI_RECEIVE_INTERRUPT);
|
65 |
|
66 | //Wait for slave to initialize
|
67 | __delay_cycles(100);
|
68 |
|
69 |
|
70 | while (1) {
|
71 |
|
72 | uiTXData = 0x11; // Holds TX data
|
73 |
|
74 | //USCI_B0 TX buffer ready?
|
75 | while (!EUSCI_B_SPI_getInterruptStatus(EUSCI_B1_BASE,
|
76 | EUSCI_B_SPI_TRANSMIT_INTERRUPT)) ;
|
77 |
|
78 | //Transmit Data to slave
|
79 | EUSCI_B_SPI_transmitData(EUSCI_B1_BASE, uiTXData);
|
80 |
|
81 | }
|