Thota Suresh Avionics
Member level 2
- Joined
- Jul 15, 2013
- Messages
- 45
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 8
- Activity points
- 345
continuing thread https://www.edaboard.com/threads/329948/
PIC24EP512GP806
MPLAB8.8V
Interfacing s25FL032P flash memory with my pic through SPI.
Are there any examples how to read and write data to flash memory using SPI ?
How do I control the mode of SPI for SCK remains at 0 for (CPOL = 0, CPHA = 0 Mode 0)
in PIC SPI register I dont find any ?
so far with some suggestions I am using SPI2 , it is not remappable.
so
PIC24EP512GP806
MPLAB8.8V
Interfacing s25FL032P flash memory with my pic through SPI.
Are there any examples how to read and write data to flash memory using SPI ?
How do I control the mode of SPI for SCK remains at 0 for (CPOL = 0, CPHA = 0 Mode 0)
in PIC SPI register I dont find any ?
so far with some suggestions I am using SPI2 , it is not remappable.
so
Code:
#define PAGESIZE 256
#define SCK TRISGbits.TRISG6
#define SDO TRISGbits.TRISG7
#define SDI TRISGbits.TRISG8
#define WP TRISEbits.TRISE5
//#define HOLD TRISEbits.TRISE6
#define CS TRISEbits.TRISE7
// For Reading Data
#define SPI_READ 0x03 // Read Data Bytes
// For Write Control
#define SPI_WREN 0x60 // Write Enable
#define SPI_WRDIS 0x04 // Write Disable
// For Erase
#define SPI_P4E 0x20 // 4KB Parameter Sector Erase
#define SPI_P8E 0x40 // 8KB(two 4KB) Parameter Sector Erase
#define SPI_SE 0xD8 // 64KB Sector Erase
#define SPI_BE 0xC7 // Bulk Erase
// For Program
#define SPI_PP 0x02 // Page Program
#define SPI_QPP 0x32 // Quad Page Program
// For Status and Configuration Register
#define SPI_RDSR 0x05 // Read Status Register
#define SPI_WRR 0x01 // Write Register
#define SPI_RCR 0x35 // Read Configuration Register
#define SPI_CLSR 0x30 // Reset the Erase and Program Fail Flag
void Config_SPI(void)
{
SCK = 0; // SCK as output
SDO = 0; // SDO as output
SDI = 1; // SDI as input
WP = 0; // WP as O/P
//HOLD = 0; // HOLD as O/P
CS = 0; // CHIP SELECT as O/P
}
void Int_SPI(void)
{
Config_SPI();
SPI2BUF = 0; // clearing Buffer
SPI2STAT = 0x0000; //
SPI2CON = 0x023B; // 8 bit mode, SPRE = 6(1:2), PPRE = 3(1:1)
SPI2STATbits.SPIEN = 1; // Enable the SPI Module.
/*
Fsck = Fcy /(Primary Prescalar * Secondary Prescalar)
Fsck = 40Mhz.
*/
}
Last edited: