CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Serial Flash SPI Memory

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

Serial Flash SPI Memory
PostPosted: Mon Aug 12, 2013 6:31 pm     Reply with quote

I am trying to program a A25L010 serial flash memory with spi serial interface.

I am use a dspic33fj64gp802. The datasheet for the memory is:
http://www.amictechnology.com/pdf/A25L512.pdf

I used the threads there (for a 25LC1024 ):
https://www.ccsinfo.com/forum/viewtopic.php?p=79877

What I need to change so to work for my memory??

The code which I used is presented below.
(When I run this code I receive the message:
Write data:4 to address:5
Read address:5 (expecting data:4), received:0
-->So is not working properly. )


Driver:
Code:

//  25LC1024  DRIVER VERSION 1

#ifndef EEPROM_SELECT
#define EEPROM_SELECT PIN_B6
#define EEPROM_CLK    PIN_B8
#define EEPROM_DI     PIN_B9
#define EEPROM_DO     PIN_B7
#endif
#define EEPROM_ADDRESS int32
#define EEPROM_SIZE    131072

void init_ext_eeprom() {
   output_high(EEPROM_SELECT);
   output_low(EEPROM_DI);
   output_low(EEPROM_CLK);
}

BOOLEAN ext_eeprom_ready() {
   BYTE cmd[1], i, data;
   cmd[0] = 0x05;                  //rdsr opcode
   output_low(EEPROM_SELECT);
   for(i=1; i<=8; ++i) {
      output_bit(EEPROM_DI, shift_left(cmd,1,0));
      output_high(EEPROM_CLK);   //data latches
      output_low(EEPROM_CLK);      //back to idle
   }

   for(i=1; i<=8; ++i) {
        output_high(EEPROM_CLK);   //data latches
        shift_left(&data,1,input(EEPROM_DO));
        output_low(EEPROM_CLK);  //back to idle
   }
     output_high(EEPROM_SELECT);
     return !bit_test(data, 0);
}

void write_ext_eeprom(EEPROM_ADDRESS address, BYTE data) {
   BYTE cmd[5];
   BYTE i;
   BYTE wren;
   wren=0x06;
   cmd[0]=data;
   cmd[1]=address;
   cmd[2]=(address>>8);
   cmd[3]=(address>>16);
   cmd[4]=0x02;
   // Wait until the eeprom is done with a previous write
   while(!ext_eeprom_ready());

   output_low(EEPROM_SELECT);
   for(i=0; i<8; ++i)
   {
      output_bit(EEPROM_DI, shift_left(&wren,1,0));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }
   output_high(EEPROM_SELECT);
   output_low(EEPROM_SELECT);
   for(i=0; i<40; ++i)
   {
      output_bit(EEPROM_DI, shift_left(cmd,5,0));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }
   output_high(EEPROM_SELECT);
}

BYTE read_ext_eeprom(EEPROM_ADDRESS address) {
   BYTE cmd[4];
   BYTE i,data;
   cmd[0]=address;
   cmd[1]=(address>>8);
   cmd[2]=(address>>16);
   cmd[3]=0x03;
   // Wait until the eeprom is done with a previous write
   while(!ext_eeprom_ready());

   output_low(EEPROM_SELECT);
   for(i=0; i<32; ++i)
   {
      output_bit(EEPROM_DI, shift_left(cmd,4,0));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }
   for(i=0; i<8; ++i)
   {
      shift_left(&data,1,input(EEPROM_DO));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }
   output_high(EEPROM_SELECT);
   return(data);
}


Main:
Code:

#include <33fj128GP802.h>
#include <25LC256_SPI.c>
#include <STDLIB.H>

// Device Specification
#FUSES NOPROTECT           
#FUSES NOIESO                 
#FUSES FRC                       
#FUSES NOWDT                 
#use delay(clock=7.37MHz) //default frequency for RC

#PIN_SELECT U1TX=PIN_B4
#PIN_SELECT U1RX=PIN_B5
#USE RS232(UART1,ERRORS,BAUD=9600)


void main()
{
int16 SPI_Temp;

init_ext_eeprom();

delay_ms(100);
OUTPUT_HIGH(PIN_A0);
printf("\n\r\n\r");
printf("Write data:4 to address:5");
write_ext_eeprom(5, 4);
delay_ms(100);
OUTPUT_low(PIN_A0);
 
SPI_Temp = read_ext_eeprom(5);
printf("\n\r");
printf("Read address:5(expecting data:4), received:%d", SPI_Temp);

while(1);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Aug 13, 2013 1:46 am     Reply with quote

There are several comments:

1) Pull up resistor on CS. This is _required_ the chip won't initialise correctly, unless CS follows the supply as power is applied. The PIC outputs are floating at this time.....
2) Pull up's on /W, and /H.
3) Are you sure the DO/DI lines are the correct way round. Remember EEPROM DO to PIC DI etc.. Calling them EEPROM_DO and DI, gets one worried....
4) Then obvious one. This code is old. It dates from before CCS offered software SPI support. The transfers can be done using:

#use spi(MASTER, CLK=PIN_B8, DI=PIN_B7, DO=PIN_B9, BAUD=500000, MODE=0, BITS=8, stream=SPI_PORT1)
//Data sheet says accepts mode 0 or 3

and spi_xfer. 90% of the code can be done 'for you', faster, and likely to be more reliable....
5) Then you are aware of the limitation of the device?. You can only program a bit from '1' to '0'. If a bit is already '0', you have to erase the page or sector (or chip). If your chip already contains zeros, then you would not be able to write '4'. To write a value to a byte, you'd have to read the page, and verify that the bits that need to be '1' are '1' in the required byte, and write. If not, then erase the page and write it back with the byte modified. These are not EEPROM's, where individual bytes can be written/erased at will.
If you want to do random byte based writes, then the alternative is to consider using a flag approach (as outlined in a Microchip AN on using the program memory of some of the PIC's to simulate EEPROM).

Best Wishes
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

Serial Flash SPI Memory
PostPosted: Tue Aug 13, 2013 7:13 pm     Reply with quote

Thanks Ttelmah for the advices. I did the following :

1) ”Pull up resistor on CS. This is _required_ the chip won't initialise correctly, unless CS follows the supply as power is applied. The PIC outputs are floating at this time.....”
-->I put a pull up resistor(1 K) at select pin

2)” Pull up's on /W, and /H.”-->Where to put pull up resistors?

3)” Are you sure the DO/DI lines are the correct way round. Remember EEPROM DO to PIC DI etc.. Calling them EEPROM_DO and DI, gets one worried.”
-->What do you mean by this? I thought that you can choose the pins you want (from the microcontroller).


4) “Then obvious one. This code is old. It dates from before CCS offered software SPI support. The transfers can be done using:
#use spi(MASTER, CLK=PIN_B8, DI=PIN_B7, DO=PIN_B9, BAUD=500000, MODE=0, BITS=8, stream=SPI_PORT1)
//Data sheet says accepts mode 0 or 3“

-->I put
Code:
#use spi(MASTER, CLK=PIN_B8, DI=PIN_B7, DO=PIN_B9, BAUD=500000, MODE=0, BITS=8, stream=SPI_PORT1)

And I remove the:
Code:

/*#ifndef EEPROM_SELECT
#define EEPROM_CLK    PIN_B8
#define EEPROM_DI     PIN_B9
#define EEPROM_DO     PIN_B7
#endif*/

From the driver file -->After the compilation I get a lot of errors

Undefined identifier EEPROM_DI
Undefined identifier EEPROM_CLK
Undefined identifier EEPROM_DO
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Aug 14, 2013 12:55 am     Reply with quote

The point about DI/DO, is that DI at the chip, is DO at the PIC. You have to get the programming of this the right way round.

Then 'of course' it won't compile with just the define. You have to replace the code that transfers data to/from the chip with spi_xfer. Something like 75% of the code can be removes and replaced with a handful of calls to this function. All of the blocks like:
Code:

   for(i=0; i<8; ++i)
   {
      output_bit(EEPROM_DI, shift_left(&wren,1,0));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }

are a single spi_xfer instruction.

The whole code probably becomes less than 20 lines, but you need to actually make the changes.
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

Serial Flash SPI Memory
PostPosted: Wed Aug 14, 2013 8:37 pm     Reply with quote

I tried to do some changes but i think there are some errors.

Where can i find any example about how to use spi_xfer ?????

The new code is presented below:
Code:

//  25LC1024  DRIVER VERSION 1

#ifndef EEPROM_SELECT
#define EEPROM_SELECT PIN_B6
#define EEPROM_CLK    PIN_B8
#define EEPROM_DI     PIN_B9
#define EEPROM_DO     PIN_B7
#endif


#define EEPROM_ADDRESS int32
#define EEPROM_SIZE    131072

#use delay(clock=7.37MHz) //default frequency for RC
#use spi(MASTER, CLK=PIN_B8, DI=PIN_B7, DO=PIN_B9, BAUD=500000, MODE=0, BITS=8, stream=SPI_PORT1)

void init_ext_eeprom() {
   output_high(EEPROM_SELECT);
   output_low(EEPROM_DI);
   output_low(EEPROM_CLK);
}


BOOLEAN ext_eeprom_ready() {
   BYTE cmd[1], i, data;

   cmd[0] = 0x05;                  //rdsr opcode

   output_low(EEPROM_SELECT);

   /*for(i=1; i<=8; ++i) {
      output_bit(EEPROM_DI, shift_left(cmd,1,0));
      output_high(EEPROM_CLK);   //data latches
      output_low(EEPROM_CLK);      //back to idle
   }*/
   spi_xfer(cmd);

   /*for(i=1; i<=8; ++i) {
        output_high(EEPROM_CLK);   //data latches
        shift_left(&data,1,input(EEPROM_DO));
        output_low(EEPROM_CLK);  //back to idle
   }*/
   spi_xfer(&data);
   
     output_high(EEPROM_SELECT);
     return !bit_test(data, 0);
}

void write_ext_eeprom(EEPROM_ADDRESS address, BYTE data) {
   BYTE cmd[5];
   BYTE i;
   BYTE wren;
   wren=0x06;
   cmd[0]=data;
   cmd[1]=address;
   cmd[2]=(address>>8);
   cmd[3]=(address>>16);
   cmd[4]=0x02;
   // Wait until the eeprom is done with a previous write
   while(!ext_eeprom_ready());

   output_low(EEPROM_SELECT);
   /*
   for(i=0; i<8; ++i)
   {
      output_bit(EEPROM_DI, shift_left(&wren,1,0));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }
   */
   spi_xfer(wren);
   
   output_high(EEPROM_SELECT);
   output_low(EEPROM_SELECT);
   
   for(i=0; i<40; ++i)
   {
      output_bit(EEPROM_DI, shift_left(cmd,5,0));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }
   
   output_high(EEPROM_SELECT);
}

BYTE read_ext_eeprom(EEPROM_ADDRESS address) {
   BYTE cmd[4];
   BYTE i,data;
   cmd[0]=address;
   cmd[1]=(address>>8);
   cmd[2]=(address>>16);
   cmd[3]=0x03;
   // Wait until the eeprom is done with a previous write
   while(!ext_eeprom_ready());

   output_low(EEPROM_SELECT);
   /*for(i=0; i<32; ++i)
   {
      output_bit(EEPROM_DI, shift_left(cmd,4,0));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }
   */
   for(i=0; i<32; ++i)
   {
   spi_xfer(cmd);
   }
   
   /*for(i=0; i<8; ++i)
   {
      shift_left(&data,1,input(EEPROM_DO));
      output_high(EEPROM_CLK);
      output_low(EEPROM_CLK);
   }*/
spi_xfer(data);
   output_high(EEPROM_SELECT);
   return(data);
}




I need a lot of advice for the code.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Thu Aug 15, 2013 1:55 am     Reply with quote

OK.
Comments in code and afterwards:
Code:

//Prototype code showing how to use spi_xfer to talk to a A25L010
//Obviously needs a memory type for the EEPROM address declared, and
//all the chip declarations.

#define WREN 6    //command defintions
#define RDSR 5
#define WRSR 1
#define RDID 0x9F
#define READ 3
#define PP 2
#define SE 0x20

#define FLASH_SELECT PIN_B6

#use spi(MASTER, CLK=PIN_B8, DI=PIN_B7, DO=PIN_B9, BAUD=500000, MODE=0, BITS=8, stream=SPI_PORT1)
//So B9, connects to the DI pin on the chip, and B7 connects to the DO?.
//Also you have got pin 7 and pin 3 on the chip both pulled up to the supply?.

BOOLEAN ext_flash_busy(void) //Return the 'busy' bit from the chip
{
   int8 data;
   output_low(FLASH_SELECT); //select chip
   spi_xfer(SPI_PORT1,RDSR); //send command to read the status register
   
   data = spi_xfer(SPI_PORT1,0); //clock out a dummy byte to get the reply
   output_high(FLASH_SELECT); //deselect chip
   return bit_test(data, 0); //return the busy flag
}

void send_address(FLASH_ADDRESS address, BYTE command) //send 24bit address & command
{
   spi_xfer(SPI_PORT1,command);
   spi_xfer(SPI_PORT1,make8(address,2)); //top byte of address
   spi_xfer(SPI_PORT1,make8(address,1)); //second byte
   spi_xfer(SPI_PORT1,make8(address,0)); //LSB
   //The original code seems to be sending the address backwards. It is MSB first
}
   
void write_ext_flash(FLASH_ADDRESS address, BYTE data[], int16 bytes_to_send) //Write 'bytes_to_send' bytes to the chip - max 256
{
   int16 count;
   // Wait until the eeprom is done with a previous write
   while(ext_flash_busy());

   output_low(FLASH_SELECT);
   spi_xfer(SPI_PORT1,WREN);
   output_high(FLASH_SELECT); //enable writing
   
   output_low(FLASH_SELECT); //now need to send the instruction, then the address
   send_address(address, PP); //select to do a page write
   //Now send however many bytes are required.
   for (count=0;count<bytes_to_send;count++)
      spi_xfer(SPI_PORT1,data[count]);       
   output_high(FLASH_SELECT); //and complete transfer
}

void page_erase(FLASH_ADDRESS address) //erase chip page
{
   while(ext_flash_busy());

   output_low(FLASH_SELECT);
   spi_xfer(WREN);
   output_high(FLASH_SELECT); //enable writing
   
   output_low(FLASH_SELECT); //now need to send the instruction, then the address
   send_address(address, SE); //select to do a sector erase
   output_high(FLASH_SELECT);
}

int8 byte_read_flash(FLASH_ADDRESS address) //read a single byte
{   
   int8 data;
   while(ext_flash_busy());
   
   output_low(FLASH_SELECT); //now need to send the instruction, then the address
   send_address(address, READ); //select to do a read
   data=spi_xfer(SPI_PORT1,0); //clock out dummy byte and read reply
   output_high(FLASH_SELECT);
   return data;
}

void block_read_flash(FLASH_ADDRESS address, BYTE data[]) //read a page into array at 'data'. Must be able to hold 256bytes
{   
   int8 count=0;
   while(ext_flash_busy());
   address &= 0xFFFF00; //make sure address points to the start of a page
   output_low(FLASH_SELECT); //now need to send the instruction, then the address
   send_address(address, READ); //select to do a read
   do
   {
      data[count]=spi_xfer(SPI_PORT1,0); //clock out dummy byte and read reply
   }
   while (count++!=255);
   output_high(FLASH_SELECT);
   return;
}
   
void main(void)
{
   BYTE data_array[256] = "Test data - just say anything"; //array to hold a page
   int8 temp;
   int8 byte_to_write;
   output_high(FLASH_SELECT);

   printf("\n\r\n\r");
   printf("Write data:4 to address:5");
   byte_to_write=4;
   //As explained, you need to verify that this byte _can_ be set to 4 before writing
   temp=byte_read_flash(5);
   if ((temp & byte_to_write) != byte_to_write)
   {
      //Here the page needs to be erased - in real code, you would have to read the page
      //to avoid losing any other data - however I'll just erase
      page_erase(5);
   }
   write_ext_flash(5, &byte_to_write, 1); //write one byte
 
   temp = byte_read_flash(5);
   printf("\n\r");
   printf("Read address:5(expecting data:4), received:%d", temp);

   //Now erase again, and write a page instead.
   page_erase(0);
   write_ext_flash(0, data_array, 256); //write an entire page - most will be garbage depending what is in the
   //chip's RAM.....
   block_read_flash(0, data_array); //read the page
   printf("\n\r string from flash %s", data_array);
   while(1);
}

Now there are several bits missing from the original code. As I said, if you read the data sheet, you can _only_ change bits from '1' to '0' when you write. You need to send a page erase command, before writing, if the byte(s) you want to write are not '1'. Hence if the byte in the chip contained '0', you would have to do a page erase before sending a '4'.

Key is that this memory is _not_ an EEPROM. It is a FLASH memory (EEPROM as a term is 'reserved' for very specific types of FLASH memory, that can do a single byte erase - this one can't).
The code you were trying to use, is for an EEPROM, that can do single byte writes without erasing. Very different....

No idea if this will work. Typed it in this morning, haven't got the chip or anything, but it shows the principle.

Best Wishes
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

Serial Flash SPI Memory
PostPosted: Thu Aug 15, 2013 8:09 pm     Reply with quote

When I use 2 (1 K) pull-up resistors at (DO,DIO) I receive the messages(when the code run):

Write data:4 to address:5
Write data:4 to address:5

If I remove the resistor pull-up form the DO, then I receive the messages(when the code run):

Read address:5(expecting data:4), received:0
string from flash
Write data:4 to address:5
Read address:5(expecting data:4), received:0
string from flash


Something is going wrong , have you got any idea?
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri Aug 16, 2013 1:12 am     Reply with quote

Why are you adding pull-ups?.

SPI does not require or want pull-ups. On long busses you can terminate with pairs of pull-up/down resistors to reduce ringing from the bus, but pull-ups like 1K, are likely just to make the drivers unable to pull the lines properly down, especially at higher rates.
On devices like SD cards, you use _large_ pull-ups (10K to 50K), to ensure the lines go high, when the card is unplugged, and slightly increase the speed of the rising edges. A large resistor like 50K, can also help to reduce overshoot at high clock rates.

It is behaving as if it is receiving '0' all the time from the memory.

Add a delay of (say) 100mSec before any transactions to the chip.
The chip requires 3mSec after the supply reaches it's operating voltage, before it can work. The PIC may well be starting several mSec before this voltage is reached.

Best Wishes
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

Serial Flash SPI Memory
PostPosted: Fri Aug 16, 2013 6:11 am     Reply with quote

I remove the pull-up resistors and i add some delay commands , but the problem is still exist.

Code:

// Device Specification
#FUSES NOPROTECT           
#FUSES NOIESO                 
#FUSES FRC                       
#FUSES NOWDT                 

//Prototype code showing how to use spi_xfer to talk to a A25L010
//Obviously needs a memory type for the EEPROM address declared, and
//all the chip declarations.

#define WREN 6    //command defintions
#define RDSR 5
#define WRSR 1
#define RDID 0x9F
#define READ 3
#define PP 2
#define SE 0x20

#define FLASH_SELECT PIN_B6

#define FLASH_ADDRESS int32
//#define EEPROM_SIZE    131072

#PIN_SELECT U1TX=PIN_B14
#PIN_SELECT U1RX=PIN_B15
#USE RS232(UART1,ERRORS,BAUD=9600)


#use spi(MASTER, CLK=PIN_B8, DI=PIN_B7, DO=PIN_B9, BAUD=500000, MODE=0, BITS=8, stream=SPI_PORT1)
//So B9, connects to the DI pin on the chip, and B7 connects to the DO?.
//Also you have got pin 7 and pin 3 on the chip both pulled up to the supply?.

BOOLEAN ext_flash_busy(void) //Return the 'busy' bit from the chip
{
   int8 data;
   output_low(FLASH_SELECT); //select chip
   spi_xfer(SPI_PORT1,RDSR); //send command to read the status register
   
   data = spi_xfer(SPI_PORT1,0); //clock out a dummy byte to get the reply
   output_high(FLASH_SELECT); //deselect chip
   return bit_test(data, 0); //return the busy flag
}

void send_address(FLASH_ADDRESS address, BYTE command) //send 24bit address & command
{
   spi_xfer(SPI_PORT1,command);
   spi_xfer(SPI_PORT1,make8(address,2)); //top byte of address
   spi_xfer(SPI_PORT1,make8(address,1)); //second byte
   spi_xfer(SPI_PORT1,make8(address,0)); //LSB
   //The original code seems to be sending the address backwards. It is MSB first
}
   
void write_ext_flash(FLASH_ADDRESS address, BYTE data[], int16 bytes_to_send) //Write 'bytes_to_send' bytes to the chip - max 256
{
   int16 count;
   // Wait until the eeprom is done with a previous write
   while(ext_flash_busy());

   output_low(FLASH_SELECT);
   spi_xfer(SPI_PORT1,WREN);
   output_high(FLASH_SELECT); //enable writing
   
   output_low(FLASH_SELECT); //now need to send the instruction, then the address
   send_address(address, PP); //select to do a page write
   //Now send however many bytes are required.
   for (count=0;count<bytes_to_send;count++)
      spi_xfer(SPI_PORT1,data[count]);       
   output_high(FLASH_SELECT); //and complete transfer
}

void page_erase(FLASH_ADDRESS address) //erase chip page
{
   while(ext_flash_busy());

   output_low(FLASH_SELECT);
   spi_xfer(WREN);
   output_high(FLASH_SELECT); //enable writing
   
   output_low(FLASH_SELECT); //now need to send the instruction, then the address
   send_address(address, SE); //select to do a sector erase
   output_high(FLASH_SELECT);
}

int8 byte_read_flash(FLASH_ADDRESS address) //read a single byte
{   
   int8 data;
   while(ext_flash_busy());
   
   output_low(FLASH_SELECT); //now need to send the instruction, then the address
   send_address(address, READ); //select to do a read
   data=spi_xfer(SPI_PORT1,0); //clock out dummy byte and read reply
   output_high(FLASH_SELECT);
   return data;
}

void block_read_flash(FLASH_ADDRESS address, BYTE data[]) //read a page into array at 'data'. Must be able to hold 256bytes
{   
   int8 count=0;
   while(ext_flash_busy());
   address &= 0xFFFF00; //make sure address points to the start of a page
   output_low(FLASH_SELECT); //now need to send the instruction, then the address
   send_address(address, READ); //select to do a read
   do
   {
      data[count]=spi_xfer(SPI_PORT1,0); //clock out dummy byte and read reply
   }
   while (count++!=255);
   output_high(FLASH_SELECT);
   return;
}
   
void main(void)
{
   BYTE data_array[256] = "Test data - just say anything"; //array to hold a page
   int8 temp;
   int8 byte_to_write;

   delay_ms(1000);
   output_high(FLASH_SELECT);

   printf("\n\r\n\r");
   printf("Write data:4 to address:5");
   byte_to_write=4;
   //As explained, you need to verify that this byte _can_ be set to 4 before writing
   temp=byte_read_flash(5);
   if ((temp & byte_to_write) != byte_to_write)
   {
      //Here the page needs to be erased - in real code, you would have to read the page
      //to avoid losing any other data - however I'll just erase
      page_erase(5);
   }
   
   delay_ms(1000);
   write_ext_flash(5, &byte_to_write, 1); //write one byte
   

  delay_ms(1000);
   

   temp = byte_read_flash(5);
   printf("\n\r");
   printf("Read address:5(expecting data:4), received:%d", temp);

   //Now erase again, and write a page instead.
   page_erase(0);
   write_ext_flash(0, data_array, 256); //write an entire page - most will be garbage depending what is in the
   //chip's RAM.....
   block_read_flash(0, data_array); //read the page
   printf("\n\r string from flash %s", data_array);
   while(1);
}


Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri Aug 16, 2013 7:39 am     Reply with quote

I'd put the delay _after_ raising the CS.
However provided the pull-up resistor is on this line that shouldn't matter.

Are both these question answered 'true'?

Quote:

//So B9, connects to the DI pin on the chip, and B7 connects to the DO?.
//Also you have got pin 7 and pin 3 on the chip both pulled up to the supply?.


Best Wishes
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

Serial Flash SPI Memory
PostPosted: Fri Aug 16, 2013 10:13 am     Reply with quote

//So B9, connects to the DI pin on the chip, and B7 connects to the DO?.
1)B9 -->DI and B7 -->DIO :connected

//Also you have got pin 7 and pin 3 on the chip both pulled up to the supply?.
2)Pin7(not HOLD) and pin 3 (not W) are connected with VDD


Any else to check?
marz



Joined: 21 Sep 2013
Posts: 1
Location: PAKISTAN

View user's profile Send private message

PostPosted: Sun Sep 22, 2013 1:02 am     Reply with quote

The addressing for 25LC010 is different from 27LC010, it is one byte address , in which ninth bit is combined with command, while 25LC1024 has three byte addressing command and address is in three bytes goes separately.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group