9 years, 9 months ago.

How to write an array to the SPI flash?

Hi!

Thanks a lot for the library!

I have one problem: I can't write to Flash more then 1 byte. If I try to write an array using page_program method, only first element is being written, the rest stay erased (0xFF values).

I've checked the MOSI signal and it seems ok - all the bytes are sent correctly.

My code now works inside FreeRTOS. During initialization I set up the memory erasing the chip and clearing status register:

/*Setup SPI Flash*/
SPI_flash.chip_erase();
SPI_flash.EWSR();
SPI_flash.WRSR(0x00);

Then inside the task I write an array to the memory during first call of the task, after that I'm reading the values. Debugging showed that in the input_array the first element is 0xF and the rest are 0xFF's.

static void prvFlashTest( void *pvParameters )
{
    uint8_t flash_write_buffer[6] = {0xF,0x55,0xC,0xF,0x05,0xFF};
    uint8 input_data[6];
    uint32_t flash_write_addr = 0x00;
    bool flash_write_ena = 1;

	for( ;; )
	{
        if ( flash_write_ena == 1 )
		{
			SPI_flash.page_program(flash_write_addr,flash_write_buffer,6);
			flash_write_ena = 0;
		}
		else
		{
			SPI_flash.read(flash_write_addr, input_data, 6);
		}
	}
}

What am I doing wrong?

I run SPI at 1 MHz.

Thanks in advance!

Regards, Dmitry.

Question relating to:

Driver for SST 64Mbit flash (8Mbyte) model 25VF064C including higher level methods for rewrite and buffered read/write to help optimize I/O. Can also work with other 25 series flash and … EEPROM, flash, SST

Be sure to check the return code of page_program(), and note it will only work if the sector is erased (relevant bits are all set), or if you are only erasing bits.

Use rewrite() instead of page_program(), so it will read, erase for you, and rewrite the entire sector. Or use one of the erase methods first.

posted by Dave Van Wagner 06 Feb 2015

Hi Dave!

Thanks for the reply!

What do you mean by "Be sure to check the return code of page_program()"?

Regards, Dmitry.

posted by Dmitry Medvedev 07 Feb 2015

1 Answer

9 years, 7 months ago.

HI Dave Van Wagner, please do us a favour and post an example of the library . thanks alot