SPI flash driver help

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

SPI flash driver help

Postby zazas321 » Wed Oct 27, 2021 9:19 am

Hello. I have been trying to understand how to write my own SPI driver for flash memory. I have managed to sucesfully read the manufacturer ID and device ID.

Datasheet:
https://datasheet.datasheetarchive.com/ ... 460477.pdf

According to the datasheet, there are 16,384 available pages for me to write.
I have written a function to write to a page:

Code: Select all


void FLASH_write_full_page(spi_device_handle_t spi, uint8_t* data, uint8_t size,uint8_t page)
{
    FLASH_write_enable(spi);
    spi_transaction_t t;
    memset(&t, 0, sizeof(t));       //Zero out the transaction
    uint8_t command_byte = 0x02;
    uint8_t address_bytes[3] = {0x00,0x00,page}; // least significant must be 0, the other 2 control which page?

	t.cmd=command_byte;
    t.addr=address_bytes;
    t.length = 8*size;
	t.addr=address_bytes;
    for (int i = 0;i < size ; i++){
        t.tx_data[i] = data[i];
    }
	t.flags=SPI_TRANS_USE_TXDATA;

    spi_device_polling_transmit(spi, &t);
}
Which one is considered to be 8 least significant bits in my case?:
uint8_t address_bytes[3] = {this,0x00,page};
or
uint8_t address_bytes[3] = {0x00,0x00,this};


I cannot fully understand what is the correct way to set the address_bytes. In the documentation it says that 8 least significant bit should be set to 0 if writing an entire page, does that mean that the remaining 16 bits are for selecting which page I want to write?
For example I have 3 bytes of data and I want to write it to the page. I know that the page is 256 bytes, but I just want to write 3 bytes at the moment.
Is the following correct?

Code: Select all

uint8_t data_tx[3] = {0x01, 0x03, 0x05};
FLASH_write_full_page(external_flash,data_tx,sizeof(data_tx));
In my page now I expect to have :
0x01, 0x03, 0x05, 0xFF, 0xFF, 0xFF, 0xFF ...........

Who is online

Users browsing this forum: No registered users and 99 guests