-
Notifications
You must be signed in to change notification settings - Fork 10
/
scratch_flash.c
154 lines (106 loc) · 2.45 KB
/
scratch_flash.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
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* scratch_flash.c
*
* Created on: Oct 11, 2016
* Author: Brent
*/
#include "scratch_flash.h"
#include "Faraday_HAL/SPI.h"
#include "cc430f6137.h"
#include "FLASH/SPI_FLASH.h"
void flash_test(void){
//////////Read Manufacturing / Device ID
volatile unsigned char databytes[4];
Faraday_FLASH_CE_Enable();
Faraday_FLASH_Hold_Disable();
__delay_cycles(50);
//Send the READ command
spi_tx(0x90);
//Send 3 dummy bytes
spi_tx(0x00);
spi_tx(0x00);
spi_tx(0x00);
//4 read bytes
unsigned char i;
for(i=0;i<4;i++){
spi_tx(0x00);
__delay_cycles(50);
databytes[i] = UCB0RXBUF;
}
Faraday_FLASH_CE_Disable();
__delay_cycles(50);
__no_operation();
///////// Read Status Register
Faraday_FLASH_CE_Enable();
Faraday_FLASH_Hold_Disable();
__delay_cycles(50);
//Send the Read Status Byte command
spi_tx(0x05);
__delay_cycles(50); //Seem to need some delay at least
spi_tx(0x00);
__delay_cycles(50);
volatile unsigned char status_byte;
status_byte = UCB0RXBUF;
__delay_cycles(50);
Faraday_FLASH_CE_Disable();
/////////Write Enable
Faraday_FLASH_CE_Enable();
Faraday_FLASH_Hold_Disable();
__delay_cycles(50);
//Send the WRITE ENABLE command
spi_tx(0x06);
__delay_cycles(50);
//Faraday_FLASH_CE_Disable();
__delay_cycles(50);
///////// Read Status Register
Faraday_FLASH_CE_Enable();
Faraday_FLASH_Hold_Disable();
__delay_cycles(50);
//Send the Read Status Byte command
spi_tx(0x05);
__delay_cycles(50); //Seem to need some delay at least
spi_tx(0x00);
__delay_cycles(50);
volatile unsigned char status_byte2;
status_byte2 = UCB0RXBUF;
__delay_cycles(50);
Faraday_FLASH_CE_Disable();
/////////Write Data
Faraday_FLASH_CE_Enable();
Faraday_FLASH_Hold_Disable();
__delay_cycles(50);
//Send the PAGE WRITE command
spi_tx(0x02);
//Send 3 address bytes MSB
spi_tx(0x00);
spi_tx(0x00);
spi_tx(0x00);
//Send 4 DATA bytes
spi_tx(0x00);
spi_tx(0x01);
spi_tx(0x02);
spi_tx(0x03);
Faraday_FLASH_CE_Disable();
__delay_cycles(50);
__no_operation();
///////////Read Memory Address (Device ID?)
volatile unsigned char databytes2[4];
Faraday_FLASH_CE_Enable();
Faraday_FLASH_Hold_Disable();
__delay_cycles(50);
//Send the READ command
spi_tx(0x03);
//Send 3 address bytes MSB
spi_tx(0x00);
spi_tx(0x00);
spi_tx(0x00);
//4 read bytes
for(i=0;i<4;i++){
spi_tx(0x00);
__delay_cycles(50);
databytes2[i] = UCB0RXBUF;
}
Faraday_FLASH_CE_Disable();
__delay_cycles(50);
__no_operation();
}