dspic33 external flash memory

Status
Not open for further replies.

Tom2

Full Member level 5
Joined
Nov 11, 2006
Messages
318
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Activity points
3,457
I will need to connect a flash memory (a25l010) with dspic33 via spi.
I tried to modify the following code but I will need advice how to do it?

the code which i used is presented bellow :
Code:
#include <p33fj64gp802.h>
// I/O definitions
#define CSEE 	_RB12		// select line for Serial EEPROM
#define TCSEE 	_TRISB12	// tris control for CSEE pin

// peripheral configurations
#define SPI_MASTER  0x0120	// select 8-bit master mode, CKE=1, CKP =0
#define SPI_ENABLE	0x8000	// enable SPI port, clear status

// 25LC256 Serial EEPROM commands
#define SEE_WRSR	1		// write status register	
#define SEE_WRITE	2		// write command
#define SEE_READ	3		// read command
#define SEE_WDI		4 		// write disable
#define SEE_STAT	5		// read status register
#define SEE_WEN		6		// write enable


// send one byte of data and receive one back at the same time
int writeSPI2( int i)
{
    SPI2BUF = i;					// write to buffer for TX
    while( !SPI2STATbits.SPIRBF);	// wait for transfer to complete
    return SPI2BUF;    				// read the received value
}//writeSPI2


int main()
{
	int i;
	
	// 1. init the SPI peripheral 
	TCSEE = 0;				// make SSEE pin output
	CSEE = 1;				// de-select the Serial EEPROM
    SPI2CON1 = SPI_MASTER;  // select mode
    SPI2STAT = SPI_ENABLE;  // enable the peripheral

	// 2. main loop
	while( 1)
	{	
    	// 2.1 send a Write Enable command
	    CSEE = 0;				// select the Serial EEPROM
	    writeSPI2( SEE_WEN);	// write enable command
	    CSEE = 1;				// deselect to complete the command
	    
	    // 2.2 Check the Serial EEPROM status 
	    CSEE = 0;				// select the Serial EEPROM
	    writeSPI2( SEE_STAT);  	// send a READ STATUS COMMAND
	    i = writeSPI2( 0);		// send/receive
	    CSEE = 1;				// deselect to terminate command
	    } // main loop
return 0;    
} // main

The datasheet for the memory is presented to attachment file.
 

Attachments

  • A25L010.pdf
    588.9 KB · Views: 42

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…