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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
| /* ************************************************************************** */
#include "system_definitions.h"
#include "my_spi_pic32.h"
/* ************************************************************************** */
/* ************************************************************************** */
/* Section: Included Files */
/* ************************************************************************** */
/* ************************************************************************** */
/* This section lists the other files that are included in this file.
*/
/* TODO: Include other files here if needed. */
unsigned int data_256[256]; /* global array to store read data */
unsigned int block_protection_18[18]; /* global array to store block_protection data */
unsigned char Manufacturer_Id, Device_Type, Device_Id; /* global array to store Manufacturer and Device id information */
/* ************************************************************************** */
/* ************************************************************************** */
/* Section: File Scope or Global Data */
/* ************************************************************************** */
/* ************************************************************************** */
/* A brief description of a section can be given directly below the section
banner.
*/
/* ************************************************************************** */
/** Descriptive Data Item Name
@Summary
Brief one-line summary of the data item.
@Description
Full description, explaining the purpose and usage of data item.
<p>
Additional description in consecutive paragraphs separated by HTML
paragraph breaks, as necessary.
<p>
Type "JavaDoc" in the "How Do I?" IDE toolbar for more information on tags.
@Remarks
Any additional remarks
*/
int global_data;
// internal type definition
typedef union
{
struct
{
uint8_t uint8Address[4];
};
uint32_t uint32Address;
} SST26_ADDRESS;
/************************************************************************/
/* PROCEDURE: Page_Program */
/* */
/* This procedure does page programming. The destination */
/* address should be provided. */
/* The data array of 256 bytes contains the data to be programmed. */
/* Since the size of the data array is 256 bytes rather than 256 bytes, this page program*/
/* procedure programs only 256 bytes */
/* Assumption: Address being programmed is already erased and is NOT */
/* block protected. */
/* Input: */
/* Dst: Destination Address 000000H - 7FFFFFH */
/* data_256[256] containing 256 bytes of data will be programmed using this function */
/************************************************************************/
void APP_SPI_CS_SELECT(void)
{
CS1_SPI=0;
}
void APP_SPI_CS_DESELECT(void)
{
CS1_SPI=1;
}
void APP_SPI_CS2_SELECT(void)
{
CS2_SPI=0;
}
void APP_SPI_CS2_DESELECT(void)
{
CS2_SPI=1;
}
void Reset1_Hold_Low()
{
RST1_FLASH=0;
}
void Reset1_Hold_High()
{
RST1_FLASH=1;
}
void Reset2_Hold_Low()
{
RST2_FLASH=0;
}
void Reset2_Hold_High()
{
RST2_FLASH=1;
}
void WP1_Low()
{
WP1_FLASH=0;
}
void WP1_High()
{
WP1_FLASH=1;
}
void WP2_Low()
{
WP2_FLASH=0;
}
void WP2_High()
{
WP2_FLASH=1;
}
void SPI_Page_Program(unsigned long Dst)
{
unsigned int i;
i=0;
APP_SPI_CS_SELECT();
DRV_SPI_Put(0x02);
DRV_SPI_Put(((Dst & 0xFFFFFF) >> 16));
DRV_SPI_Put(((Dst & 0xFFFF) >> 8));
DRV_SPI_Put(Dst & 0xFF);
for (i=0;i<256;i++)
{ DRV_SPI_Put(data_256[i]); /* send byte to be programmed */
}
APP_SPI_CS_DESELECT(); /* disable device */
}
/************************************************************************/
/* PROCEDURE: Read_Status_Register */
/* */
/* This procedure reads the status register and returns the byte. */
/************************************************************************/
unsigned char SPI_Read_Status_Register()
{
unsigned char byte = 0;
APP_SPI_CS_SELECT();/* enable device */
DRV_SPI_Put(0x05);
//Send_Byte(0x05); /* send RDSR command */
byte = DRV_SPI_read(); /* receive byte */
APP_SPI_CS_DESELECT(); /* disable device */
return byte;
}
/************************************************************************/
/* PROCEDURE: WREN */
/* */
/* This procedure enables the Write Enable Latch. */
/************************************************************************/
void SPI_WREN()
{
//APP_SPI_CS_SELECT();/* enable device */
DRV_SPI_Put(0x06);
//Send_Byte(0x06); /* send WREN command */
//APP_SPI_CS_DESELECT(); /* disable device */
}
/************************************************************************/
/* PROCEDURE: WRDI */
/* */
/* This procedure disables the Write Enable Latch. */
/************************************************************************/
void SPI_WRDI()
{
//APP_SPI_CS_SELECT();/* enable device */
DRV_SPI_Put(0x04);
//Send_Byte(0x04); /* send WRDI command */
//APP_SPI_CS_DESELECT(); /* disable device */
}
/************************************************************************/
/* PROCEDURE: QuadJ_ID */
/* */
/* This procedure Reads the manufacturer's ID, device Type and device ID. It will */
/* use AFh as the command to read the ID. */
/* Returns: */
/* ID1(Manufacture's ID = BFh, Device Type =26h , Device ID = 02h) */
/* */
/************************************************************************/
void Jedec_ID_Read()
{
//APP_SPI_CS_SELECT();/* enable device */
DRV_SPI_Put(0x9F);
//DRV_SPI_Put(0x9F);
//DRV_SPI_Put(0x9F);
Manufacturer_Id = DRV_SPI_read();
Device_Type = DRV_SPI_read();
Device_Id = DRV_SPI_read();
Manufacturer_flash=Manufacturer_Id;
Device_type_flash=Device_Type;
Device_Id_flash=Device_Id;
} |
Partager