Subversion Repositories Code-Repo

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
249 Kevin 1
#include <msp430.h> 
2
#include "defines.h"
3
#include "spi.h"
4
 
5
int main(void) {
6
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
7
 
8
    /* --- Set Oscillator Settings (8Mhz) --------------- */
9
    // Set DCO to 5, MOD to 0
10
    DCOCTL = DCO2 | DCO0;
11
    // Set RSEL to 13
12
	BCSCTL1 = RSEL3 | RSEL2 | RSEL0;
13
	// MCLK = DCO/1, SMCLK = MCLK/8
14
	BCSCTL2 = SELM_0 | DIVM_0 | DIVS_3;
15
	// LFXT1 = VLOCLK, 1pF termination
16
	BCSCTL3 = LFXT1S_2 | XCAP_0;
17
	// Disable oscillator fault interrupt
18
	IE1 &= ~OFIE;
19
	/* -------------------------------------------------- */
20
 
21
	/* --- Set Port Settings ---------------------------- */
22
	// Set ports 1.5/1.6 as outputs
23
	// Set remaining ports as inputs
24
	P1DIR = BIT5 | BIT6;
25
	P2DIR = 0x00;
26
	// Enable pull-down resistors
27
	P1REN = ~(BIT5 | BIT6);
28
	P2REN = 0xFF;
29
	// Set initial port values
30
	P1OUT = 0x00;
31
	P2OUT = 0x00;
32
	/* -------------------------------------------------- */
33
 
34
	/* --- Set USI Settings (SPI) ----------------------- */
35
	// Enable SDA/SCL/SCLK ports, MSB->LSB, master mode, output enabled
36
	USICTL0 = USIPE7 | USIPE6 | USIPE5 | USIMST | USIOE;
37
	// I2C disabled, counter interrupt enabled
38
	USICTL1 = USIIE;
39
	// SMCLK/1, SMCLK source, idle low
40
	USICKCTL = USIDIV_0 | USISSEL_2;
41
	// Enable USI module (clear reset bit)
42
	USICTL0 &= ~USISWRST;
43
	/* -------------------------------------------------- */
44
 
45
	// Write 0 to the counter to trigger the USI interrupt
46
//	USICNT = 0;
47
 
48
	// Go into low power mode with interrupts enabled
49
	_BIS_SR(LPM0_bits + GIE);
50
}
51
 
52
#pragma vector=USI_VECTOR
53
__interrupt void USI_SPI_Vector(void) {
54
	char value = USISR;
55
	USISR = 0xAB;
56
	USICNT = 8;
57
}