-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspi.h
60 lines (51 loc) · 1.74 KB
/
spi.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef USCI_SPI_H
#define USCI_SPI_H
#include <msp430.h>
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* USCI A0 Master-In-Slave-Out (MISO) NOT USED
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* GPIO : P1.1
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#define USCIA0_MISO_BIT BIT1
#define USCIA0_MISO_PORT P1IN
#define USCIA0_MISO_DDR P1DIR
#define SET_USCIA0_MISO_AS_AN_INPUT USCIA0_MISO_DDR &= ~USCIA0_MISO_BIT
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* USCI A0 Master-Out-Slave-In (MOSI) FOR 7 SEGMENT DISPLAY
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* GPIO : P1.7
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#define USCIA0_MOSI_BIT BIT7
#define USCIA0_MOSI_PORT P1OUT
#define USCIA0_MOSI_DDR P1DIR
#define SET_USCIA0_MOSI_AS_AN_OUTPUT USCIA0_MOSI_DDR |= USCIA0_MOSI_BIT
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Slave Clock for GPIO Flash Memory Board FOR 7 SEGMENT DISPLAY
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* GPIO : P1.5
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#define SPI_SCK_BIT BIT5
#define SPI_SCK_PORT P1OUT // SPI Slave Clock output
#define SPI_SCK_DDR P1DIR // SPI Slave Clock direction
#define SET_SPI_SCK_AS_AN_OUTPUT SPI_SCK_DDR |= SPI_SCK_BIT
#define TOGGLE_SCK SPI_SCK_PORT ^= SPI_SCK_BIT // Toggle Clock!
#define RISE_SCK SPI_SCK_PORT |= SPI_SCK_BIT
#define FALL_SCK SPI_SCK_PORT &= ~(SPI_SCK_BIT)
/*
* This function initializes all hardware and port pins to support SPI.
*/
void InitializeSPI();
/*
* This function sends the byte, SendValue, using SPI.
*/
void SPISendByte(unsigned char SendValue);
/*
* This function receives a byte using SPI.
*
* Return Value: The byte that is received over SPI.
*/
unsigned char SPIReceiveByte();
#endif