SPI1CON1bits.SPRE1 = 1;
SPI1CON1bits.SPRE0 = 1;
SPI1CON2 = 0;
SPI1STATbits.SPIEN = 1;
*/
/*
Example setup for PIC32 family://----- SETUP SPI 1 ----//Used for: Flash Memory
//Idle low, active high
//Transmit on active to idle (falling edge)
SpiChnOpen(SPI_CHANNEL1, (SPI_CON_MSTEN | SPI_OPEN_CKE_REV | SPI_CON_MOD
E8), 2);
//40MHz fpb / 2 = 20MHz
*/
//##### ADDING A FUNCTION TO READ INDVIDIUAL BYTES USING A LOCAL BUFFER FOR A PA
GE OF MEMORY#####
//Add to INTERNAL ONLY MEMORY DEFINITIONS:/*
DWORD flash_buffer_address = 0xffffffff;
BYTE flash_buffer[256];
*/
//Add to fucntion definitions
/*
BYTE flash_read_byte (DWORD address);
extern BYTE flash_read_byte (DWORD address);
*/
//Add this function://*******************************
//*******************************
//********** READ BYTE **********
//*******************************
//*******************************
/*
BYTE flash_read_byte (DWORD address)
{
//LOAD PAGE IF NECESSARY
if ((flash_buffer_address & 0xffffff00) != (address & 0xffffff00))
{
flash_buffer_address = (address & 0xffffff00);
flash_read_page(flash_buffer_address, &flash_buffer[0]);
}
return(flash_buffer[(address & 0x000000ff)]);
}
*/
//*****************************
//*****************************
//********** DEFINES **********
//*****************************
//*****************************
#ifndef FLASH_C_INIT
//Do only once the first time this file is used
#define FLASH_C_INIT
//---------------------------//----- FLASH MEMORY MAP ----//---------------------------//AT45DB081, FLASH MEMORY
//1048576 bytes x 8 (1024KB / 1MB)
//4096 pages of 256 bytes (To avoid non binary complexities this driver only use
s 256 bytes of each page instead of the 264 which are actually available)
//0x000000 - 0x0fffff
//
//4096 pages of 256 bytes
//512 blocks of 2 Kbytes
//16 sectors of 64 Kbytes
//
//The AT45DB081 is shipped with the page size set to 264 bytes. This driver lea
ves it set to 264 bytes and adjusts it's addressing accordingly. When calling i
t's
//functions you use normal binary addressing and can ignore the 264 byte page si
ze issue.
#define FLASH_END_ADDRESS
#define FLASH_BLOCK_SIZE
k is 8 pages
//##################
//##### PIC 18 #####
//##################
/*
#define FLASH_CLR_WDT
watchdog timer
//----- PINS ----#define FLASH_CS(state)
0x0fffff
0x800
ClrWdt()
//A bloc
//Clear
LATCbits.LATC0 = state
Nop(); Nop()
//#####################
//##### DSPIC33FJ #####
//#####################
/*
#define FLASH_CLR_WDT
watchdog timer
//----- PINS ----#define FLASH_CS(state)
ClrWdt()
//Clear
_LATF5 = state
Nop(); Nop()
ClrWdt()
//Clear
_LATG15 = state
Nop(); Nop()
ClearWDT()
//Clear
SpiChnDataRdy(SPI_CHANNE
L1)
//>0 when the SPI receive buffer
contains a received byte, also signifying that transmit is complete
#define FLASH_SPI_READ_BUFFER
(BYTE)SpiChnReadC(SPI_CHANNEL1)
//Register to read last received byte from
#define FLASH_SPI_WRITE_BUFFER(data)
SpiChnWriteC(SPI_CHANNEL1, (unsigned int
)data) //Macro to write a byte and start transmission over the SPI bus
#define DO_CS_HIGH_DELAY
//Delay of at least 50nS
#endif
//#ifndef FLASH_C_INIT
//*******************************
//*******************************
//********** FUNCTIONS **********
//*******************************
//*******************************
#ifdef FLASH_C
//----------------------------------//----- INTERNAL ONLY FUNCTIONS ----//----------------------------------BYTE flash_read_status (void);
//----------------------------------------//----- INTERNAL & EXTERNAL FUNCTIONS ----//----------------------------------------//(Also defined below as extern)
BYTE flash_check_present (void);
void flash_erase_page (DWORD address);
void flash_erase_block (DWORD address);
void flash_erase_all (void);
void flash_write_page (DWORD address, BYTE *buffer, BYTE erase_first);
void flash_read_page (DWORD address, BYTE *buffer);
BYTE flash_test_memory (void);
#else
//-----------------------------//----- EXTERNAL FUNCTIONS ----//-----------------------------extern BYTE flash_check_present (void);
extern void flash_erase_page (DWORD address);
extern void flash_erase_block (DWORD address);
extern void flash_erase_all (void);
extern void flash_write_page (DWORD address, BYTE *buffer, BYTE erase_first);
extern void flash_read_page (DWORD address, BYTE *buffer);
extern BYTE flash_test_memory (void);
#endif
//****************************
//****************************
//-------------------------------------------------//----- INTERNAL & EXTERNAL MEMORY DEFINITIONS ----//-------------------------------------------------//(Also defined below as extern)
#else
//--------------------------------------//----- EXTERNAL MEMORY DEFINITIONS ----//---------------------------------------
#endif