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);
}
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));
0x01, 0x03, 0x05, 0xFF, 0xFF, 0xFF, 0xFF ...........