-
Notifications
You must be signed in to change notification settings - Fork 2
/
spi.c
28 lines (22 loc) · 667 Bytes
/
spi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Functions to setup, transmit and receive data over the SPI interface
#include <io.h>
#include "spi.h"
#include "softDelay.h"
/** \file spi.c
*/
/** Initialise spi interface on uart0.
Set for 8 bits data, master, 3 pin mode.
Uses SMCLK with divide set to 2 (ie maximum speed). Interrupts disabled.
*/
void spiInit(void)
{
U0CTL = 0x17; // SPI, 8 bit data, no loopback, SPI mode, master, reset
U0TCTL = 0xa3; // CKPH=1, CKPL=0, SMCLK, 3 pin mode, Tx empty
U0BR0 = 2; // smclk divider
U0BR1 = 0;
U0MCTL = 0; // not used, but should be 0
IE1 &= ~0x80; // disable interrupts
IE1 &= ~0x40;
ME1 |= 0x40; // enable spi module
U0CTL &= ~1; // release reset
}