Function Documentation

void power_down_flash_ram

(

void

)

Issue the command to put the M25P16 into power down mode.

In Power down mode the device ignores all erase and program instructions.

In this mode the device draws 1uA typically. Use the power_up_flash_ram() command to bring the device out of power down mode. Removing power completely will also cancel the Deep power down mode - it will power up again in standby mode.

void power_up_flash_ram

(

void

)

Issue the command to bring the M25P16 out of power down mode.

This function has no effect if the device is currently in one of the erase modes. At power up the deice will be in standby mode, there is no need to issue the power_up_flash_ram() command after a power up.

void ram_bulk_erase

(

)

Erase the M25P16.

This function issues an erase command, then blocks until the command is complete as shown by the status register being zero. Note that the erase actually sets all bits to 1. The page program can set bits to 0, but NOT to 1. Therefore each page should be considered 'write once' between erase cycles.

void ram_sector_erase

(

uint8_t

sector

)

Erase 1 sector of the M25P16.

Parameters:

sector

The sector number (0-31) to be erased.

This function issues a sector erase command, then blocks until the command is complete as shown by the status register being zero For future expansion, no masking of the sector byte to ensure that it does not contain values >31 takes place Note that the erase actually sets all bits to 1. The page program can set bits to 0, but NOT to 1. Therefore each page should be considered 'write once' between erase cycles.

void read_flash_page

(

uint8_t

flash_sector,

uint8_t

flash_page,

uint8_t *

mem_ptr

)

Read exactly 256 bytes from the selected page of the M25P16 to memory.

Parameters:

flash_sector

Sector number in the M25P16, range 0..31.

flash_page

Page number in the sector.

*mem_ptr

Pointer to the data location in memory

The function will carry out the write enable instruction as part of the write The 256 bytes will be exactly aligned with a 256 byte boundary in the memory

For reads or writes of less than 256 bytes, or non aligned read or writes use the read_write_flash_ram() function instead.

void read_ram_id

(

uint8_t *

mem_ptr

)

Read 3 bytes of ID from the M25P16. These should always be 0x20,0x20,0x15.

Parameters:

*mem_ptr

Pointer to location to store values returned.

uint8_t read_ram_status

(

)

Select the M25P16 and return 1 byte from the Status register.

Returns:

returns device status byte.

void read_write_flash_ram

(

uint8_t

one_read_zero_write,

uint16_t

bytes_to_readwrite,

uint8_t

flash_sector,

uint8_t

flash_page,

uint8_t

offset,

uint8_t *

mem_ptr

)

Perform an arbirary read/write from/to the M25P16.

Parameters:

one_read_zero_write

Any non-zero value will execute a read from the M25P16, 0 will execute a write to the M25P16

bytes_to_readwrite

uint16_t Number of bytes to read or write. Values will typically be less than or exactly 256. See below for why.

flash_sector

Sector number in the M25P16, range 0..31.

flash_page

Page number in the sector.

offset

Position in the page at which to start the read/write

*mem_ptr

Pointer to memory location for read/write data

This function would typically only be used for reads or writes of <256 bytes.

IMPORTANT The M25P16 is a block device. It deals in 256 byte pages. Writes only every take place to a single 256 byte page. If writing >256 bytes, anything other than the last 256 bytes will be overwritten and ignored. If offset is non-zero, then be aware that if offset+bytes_to_readwrite > 255, then any write will wrap back to the beginning of the page. This is unlikely to be what you want.

void write_flash_page

(

uint8_t

flash_sector,

uint8_t

flash_page,

uint8_t *

mem_ptr

)

Write exactly 256 bytes to the selected page of the M25P16 from memory.

Parameters:

flash_sector

Sector number in the M25P16, range 0..31.

flash_page

Page number in the sector.

*mem_ptr

Pointer to the data location in memory

The 256 bytes will be exactly aligned with a 256 byte boundary in the memory Writing 256 bytes at a time is the most efficient way to write to this device

For reads or writes of less than 256 bytes, or non aligned read or writes use the read_write_flash_ram() function instead.

void write_ram_status

(

uint8_t

status

)

Write to the status register on the M25P16.

Parameters:

status

Value to write

This function blocks until the bottom bit of the status register is clear = device ready.