\hypertarget{m25p16_8h}{
\section{m25p16.h File Reference}
\label{m25p16_8h}\index{m25p16.h@{m25p16.h}}
}
{\tt \#include $<$avr/io.h$>$}\par
{\tt \#include $<$config.h$>$}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define \hyperlink{m25p16_8h_575650e71d102913f03c67fcfc8f62b4}{RAM\_\-WREN}~0x06
\item 
\#define \hyperlink{m25p16_8h_c843ddc6a309039c80a06fde19e9691d}{RAM\_\-WRDI}~0x04
\item 
\#define \hyperlink{m25p16_8h_bcad2903f143ee02341c92499fdc3fc6}{RAM\_\-RDID}~0x9F
\item 
\#define \hyperlink{m25p16_8h_8f83d15653e4887de9f634dd6282b9f4}{RAM\_\-RDSR}~0x05
\item 
\#define \hyperlink{m25p16_8h_75fe849e20879e63440d7910a49e5690}{RAM\_\-WRSR}~0x01
\item 
\#define \hyperlink{m25p16_8h_03c074a7558839cecf6a6d6be5790318}{RAM\_\-READ}~0x03
\item 
\#define \hyperlink{m25p16_8h_1724ee8ca74ed0f041686ac448fbf820}{RAM\_\-FASTREAD}~0x0B
\item 
\#define \hyperlink{m25p16_8h_a541a0b053424130a5f105ae2df98a94}{RAM\_\-PP}~0x02
\item 
\#define \hyperlink{m25p16_8h_f9efa89a2475b0bac3069c948977ba60}{RAM\_\-SE}~0xD8
\item 
\#define \hyperlink{m25p16_8h_30d0b196a4116ae7070a37e69ef9a3c6}{RAM\_\-BE}~0xC7
\item 
\#define \hyperlink{m25p16_8h_a11343415ad91442b02a5ea7358fff56}{RAM\_\-DP}~0xB9
\item 
\#define \hyperlink{m25p16_8h_3ffc7994ed1346b04c4cd6ccc40e47e1}{RAM\_\-RES}~0xAB
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{m25p16_8h_6ab730c1273c2eec636c189418466484}{read\_\-ram\_\-id} (uint8\_\-t $\ast$mem\_\-ptr)
\begin{CompactList}\small\item\em Read 3 bytes of ID from the M26P16. These should always be 0x20,0x20,0x15. \item\end{CompactList}\item 
uint8\_\-t \hyperlink{m25p16_8h_91c3ddb4467bebfd74fd97422dba5a65}{read\_\-ram\_\-status} (void)
\begin{CompactList}\small\item\em Select the M25P16 and return 1 byte from the Status register. \item\end{CompactList}\item 
void \hyperlink{m25p16_8h_115063c9b07a389203e888f8bf5f7262}{ram\_\-bulk\_\-erase} (void)
\begin{CompactList}\small\item\em Erase the M25P16. \item\end{CompactList}\item 
void \hyperlink{m25p16_8h_f11b4c9ff8a3ded8e9980bc3c95ab475}{ram\_\-sector\_\-erase} (uint8\_\-t sector)
\begin{CompactList}\small\item\em Erase 1 sector of the M25P16. \item\end{CompactList}\item 
void \hyperlink{m25p16_8h_a0b75960351bb943a848bd22a07208fe}{write\_\-flash\_\-page} (uint8\_\-t flash\_\-sector, uint8\_\-t flash\_\-page, uint8\_\-t $\ast$mem\_\-ptr)
\begin{CompactList}\small\item\em Write exactly 256 bytes to the selected page of the M26P16 from memory. \item\end{CompactList}\item 
void \hyperlink{m25p16_8h_e4efe39e53bf06f114635e8030173021}{read\_\-flash\_\-page} (uint8\_\-t flash\_\-sector, uint8\_\-t flash\_\-page, uint8\_\-t $\ast$mem\_\-ptr)
\begin{CompactList}\small\item\em Read exactly 256 bytes from the selected page of the M26P16 to memory. \item\end{CompactList}\item 
void \hyperlink{m25p16_8h_685b042fbdf45ec7f6f34982348e0851}{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 $\ast$mem\_\-ptr)
\begin{CompactList}\small\item\em Perform an arbirary read/write from/to the M26P16. \item\end{CompactList}\item 
void \hyperlink{m25p16_8h_aaeb96e65402cac033dfee993d07e758}{write\_\-ram\_\-status} (uint8\_\-t status)
\begin{CompactList}\small\item\em Write to the status register on the M25P16. \item\end{CompactList}\item 
void \hyperlink{m25p16_8h_72320c79176360eda61bbdec456c0cb8}{power\_\-up\_\-flash\_\-ram} (void)
\begin{CompactList}\small\item\em Issue the command to bring the M25P16 out of power down mode. \item\end{CompactList}\item 
void \hyperlink{m25p16_8h_8fb52e0403464a657a3e28a1fa536aff}{power\_\-down\_\-flash\_\-ram} (void)
\begin{CompactList}\small\item\em Issue the command to put the M25P16 into power down mode. \item\end{CompactList}\end{CompactItemize}


\subsection{Define Documentation}
\hypertarget{m25p16_8h_30d0b196a4116ae7070a37e69ef9a3c6}{
\index{m25p16.h@{m25p16.h}!RAM\_\-BE@{RAM\_\-BE}}
\index{RAM\_\-BE@{RAM\_\-BE}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-BE}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-BE~0xC7}}
\label{m25p16_8h_30d0b196a4116ae7070a37e69ef9a3c6}


\hypertarget{m25p16_8h_a11343415ad91442b02a5ea7358fff56}{
\index{m25p16.h@{m25p16.h}!RAM\_\-DP@{RAM\_\-DP}}
\index{RAM\_\-DP@{RAM\_\-DP}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-DP}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-DP~0xB9}}
\label{m25p16_8h_a11343415ad91442b02a5ea7358fff56}


\hypertarget{m25p16_8h_1724ee8ca74ed0f041686ac448fbf820}{
\index{m25p16.h@{m25p16.h}!RAM\_\-FASTREAD@{RAM\_\-FASTREAD}}
\index{RAM\_\-FASTREAD@{RAM\_\-FASTREAD}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-FASTREAD}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-FASTREAD~0x0B}}
\label{m25p16_8h_1724ee8ca74ed0f041686ac448fbf820}


\hypertarget{m25p16_8h_a541a0b053424130a5f105ae2df98a94}{
\index{m25p16.h@{m25p16.h}!RAM\_\-PP@{RAM\_\-PP}}
\index{RAM\_\-PP@{RAM\_\-PP}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-PP}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-PP~0x02}}
\label{m25p16_8h_a541a0b053424130a5f105ae2df98a94}


\hypertarget{m25p16_8h_bcad2903f143ee02341c92499fdc3fc6}{
\index{m25p16.h@{m25p16.h}!RAM\_\-RDID@{RAM\_\-RDID}}
\index{RAM\_\-RDID@{RAM\_\-RDID}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-RDID}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-RDID~0x9F}}
\label{m25p16_8h_bcad2903f143ee02341c92499fdc3fc6}


\hypertarget{m25p16_8h_8f83d15653e4887de9f634dd6282b9f4}{
\index{m25p16.h@{m25p16.h}!RAM\_\-RDSR@{RAM\_\-RDSR}}
\index{RAM\_\-RDSR@{RAM\_\-RDSR}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-RDSR}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-RDSR~0x05}}
\label{m25p16_8h_8f83d15653e4887de9f634dd6282b9f4}


\hypertarget{m25p16_8h_03c074a7558839cecf6a6d6be5790318}{
\index{m25p16.h@{m25p16.h}!RAM\_\-READ@{RAM\_\-READ}}
\index{RAM\_\-READ@{RAM\_\-READ}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-READ}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-READ~0x03}}
\label{m25p16_8h_03c074a7558839cecf6a6d6be5790318}


\hypertarget{m25p16_8h_3ffc7994ed1346b04c4cd6ccc40e47e1}{
\index{m25p16.h@{m25p16.h}!RAM\_\-RES@{RAM\_\-RES}}
\index{RAM\_\-RES@{RAM\_\-RES}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-RES}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-RES~0xAB}}
\label{m25p16_8h_3ffc7994ed1346b04c4cd6ccc40e47e1}


\hypertarget{m25p16_8h_f9efa89a2475b0bac3069c948977ba60}{
\index{m25p16.h@{m25p16.h}!RAM\_\-SE@{RAM\_\-SE}}
\index{RAM\_\-SE@{RAM\_\-SE}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-SE}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-SE~0xD8}}
\label{m25p16_8h_f9efa89a2475b0bac3069c948977ba60}


\hypertarget{m25p16_8h_c843ddc6a309039c80a06fde19e9691d}{
\index{m25p16.h@{m25p16.h}!RAM\_\-WRDI@{RAM\_\-WRDI}}
\index{RAM\_\-WRDI@{RAM\_\-WRDI}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-WRDI}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-WRDI~0x04}}
\label{m25p16_8h_c843ddc6a309039c80a06fde19e9691d}


\hypertarget{m25p16_8h_575650e71d102913f03c67fcfc8f62b4}{
\index{m25p16.h@{m25p16.h}!RAM\_\-WREN@{RAM\_\-WREN}}
\index{RAM\_\-WREN@{RAM\_\-WREN}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-WREN}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-WREN~0x06}}
\label{m25p16_8h_575650e71d102913f03c67fcfc8f62b4}


\hypertarget{m25p16_8h_75fe849e20879e63440d7910a49e5690}{
\index{m25p16.h@{m25p16.h}!RAM\_\-WRSR@{RAM\_\-WRSR}}
\index{RAM\_\-WRSR@{RAM\_\-WRSR}!m25p16.h@{m25p16.h}}
\subsubsection[{RAM\_\-WRSR}]{\setlength{\rightskip}{0pt plus 5cm}\#define RAM\_\-WRSR~0x01}}
\label{m25p16_8h_75fe849e20879e63440d7910a49e5690}




\subsection{Function Documentation}
\hypertarget{m25p16_8h_8fb52e0403464a657a3e28a1fa536aff}{
\index{m25p16.h@{m25p16.h}!power\_\-down\_\-flash\_\-ram@{power\_\-down\_\-flash\_\-ram}}
\index{power\_\-down\_\-flash\_\-ram@{power\_\-down\_\-flash\_\-ram}!m25p16.h@{m25p16.h}}
\subsubsection[{power\_\-down\_\-flash\_\-ram}]{\setlength{\rightskip}{0pt plus 5cm}void power\_\-down\_\-flash\_\-ram (void)}}
\label{m25p16_8h_8fb52e0403464a657a3e28a1fa536aff}


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 \hyperlink{m25p16_8c_72320c79176360eda61bbdec456c0cb8}{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. \hypertarget{m25p16_8h_72320c79176360eda61bbdec456c0cb8}{
\index{m25p16.h@{m25p16.h}!power\_\-up\_\-flash\_\-ram@{power\_\-up\_\-flash\_\-ram}}
\index{power\_\-up\_\-flash\_\-ram@{power\_\-up\_\-flash\_\-ram}!m25p16.h@{m25p16.h}}
\subsubsection[{power\_\-up\_\-flash\_\-ram}]{\setlength{\rightskip}{0pt plus 5cm}void power\_\-up\_\-flash\_\-ram (void)}}
\label{m25p16_8h_72320c79176360eda61bbdec456c0cb8}


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 \hyperlink{m25p16_8c_72320c79176360eda61bbdec456c0cb8}{power\_\-up\_\-flash\_\-ram()} command after a power up. \hypertarget{m25p16_8h_115063c9b07a389203e888f8bf5f7262}{
\index{m25p16.h@{m25p16.h}!ram\_\-bulk\_\-erase@{ram\_\-bulk\_\-erase}}
\index{ram\_\-bulk\_\-erase@{ram\_\-bulk\_\-erase}!m25p16.h@{m25p16.h}}
\subsubsection[{ram\_\-bulk\_\-erase}]{\setlength{\rightskip}{0pt plus 5cm}void ram\_\-bulk\_\-erase (void)}}
\label{m25p16_8h_115063c9b07a389203e888f8bf5f7262}


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. \hypertarget{m25p16_8h_f11b4c9ff8a3ded8e9980bc3c95ab475}{
\index{m25p16.h@{m25p16.h}!ram\_\-sector\_\-erase@{ram\_\-sector\_\-erase}}
\index{ram\_\-sector\_\-erase@{ram\_\-sector\_\-erase}!m25p16.h@{m25p16.h}}
\subsubsection[{ram\_\-sector\_\-erase}]{\setlength{\rightskip}{0pt plus 5cm}void ram\_\-sector\_\-erase (uint8\_\-t {\em sector})}}
\label{m25p16_8h_f11b4c9ff8a3ded8e9980bc3c95ab475}


Erase 1 sector of the M25P16. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em sector}]The sector number (0-31) to be erased.\end{description}
\end{Desc}
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. \hypertarget{m25p16_8h_e4efe39e53bf06f114635e8030173021}{
\index{m25p16.h@{m25p16.h}!read\_\-flash\_\-page@{read\_\-flash\_\-page}}
\index{read\_\-flash\_\-page@{read\_\-flash\_\-page}!m25p16.h@{m25p16.h}}
\subsubsection[{read\_\-flash\_\-page}]{\setlength{\rightskip}{0pt plus 5cm}void read\_\-flash\_\-page (uint8\_\-t {\em flash\_\-sector}, \/  uint8\_\-t {\em flash\_\-page}, \/  uint8\_\-t $\ast$ {\em mem\_\-ptr})}}
\label{m25p16_8h_e4efe39e53bf06f114635e8030173021}


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

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em flash\_\-sector}]Sector number in the M25P16, range 0..31. \item[{\em flash\_\-page}]Page number in the sector. \item[{\em $\ast$mem\_\-ptr}]Pointer to the data location in memory\end{description}
\end{Desc}
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 \hyperlink{m25p16_8c_685b042fbdf45ec7f6f34982348e0851}{read\_\-write\_\-flash\_\-ram()} function instead. \hypertarget{m25p16_8h_6ab730c1273c2eec636c189418466484}{
\index{m25p16.h@{m25p16.h}!read\_\-ram\_\-id@{read\_\-ram\_\-id}}
\index{read\_\-ram\_\-id@{read\_\-ram\_\-id}!m25p16.h@{m25p16.h}}
\subsubsection[{read\_\-ram\_\-id}]{\setlength{\rightskip}{0pt plus 5cm}void read\_\-ram\_\-id (uint8\_\-t $\ast$ {\em mem\_\-ptr})}}
\label{m25p16_8h_6ab730c1273c2eec636c189418466484}


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

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em $\ast$mem\_\-ptr}]Pointer to location to store values returned. \end{description}
\end{Desc}
\hypertarget{m25p16_8h_91c3ddb4467bebfd74fd97422dba5a65}{
\index{m25p16.h@{m25p16.h}!read\_\-ram\_\-status@{read\_\-ram\_\-status}}
\index{read\_\-ram\_\-status@{read\_\-ram\_\-status}!m25p16.h@{m25p16.h}}
\subsubsection[{read\_\-ram\_\-status}]{\setlength{\rightskip}{0pt plus 5cm}uint8\_\-t read\_\-ram\_\-status (void)}}
\label{m25p16_8h_91c3ddb4467bebfd74fd97422dba5a65}


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

\begin{Desc}
\item[Returns:]returns device status byte. \end{Desc}
\hypertarget{m25p16_8h_685b042fbdf45ec7f6f34982348e0851}{
\index{m25p16.h@{m25p16.h}!read\_\-write\_\-flash\_\-ram@{read\_\-write\_\-flash\_\-ram}}
\index{read\_\-write\_\-flash\_\-ram@{read\_\-write\_\-flash\_\-ram}!m25p16.h@{m25p16.h}}
\subsubsection[{read\_\-write\_\-flash\_\-ram}]{\setlength{\rightskip}{0pt plus 5cm}void read\_\-write\_\-flash\_\-ram (uint8\_\-t {\em one\_\-read\_\-zero\_\-write}, \/  uint16\_\-t {\em bytes\_\-to\_\-readwrite}, \/  uint8\_\-t {\em flash\_\-sector}, \/  uint8\_\-t {\em flash\_\-page}, \/  uint8\_\-t {\em offset}, \/  uint8\_\-t $\ast$ {\em mem\_\-ptr})}}
\label{m25p16_8h_685b042fbdf45ec7f6f34982348e0851}


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

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em one\_\-read\_\-zero\_\-write}]Any non-zero value will execute a read from the M25P16, 0 will execute a write to the M25P16 \item[{\em 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. \item[{\em flash\_\-sector}]Sector number in the M25P16, range 0..31. \item[{\em flash\_\-page}]Page number in the sector. \item[{\em offset}]Position in the page at which to start the read/write \item[{\em $\ast$mem\_\-ptr}]Pointer to memory location for read/write data\end{description}
\end{Desc}
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. \hypertarget{m25p16_8h_a0b75960351bb943a848bd22a07208fe}{
\index{m25p16.h@{m25p16.h}!write\_\-flash\_\-page@{write\_\-flash\_\-page}}
\index{write\_\-flash\_\-page@{write\_\-flash\_\-page}!m25p16.h@{m25p16.h}}
\subsubsection[{write\_\-flash\_\-page}]{\setlength{\rightskip}{0pt plus 5cm}void write\_\-flash\_\-page (uint8\_\-t {\em flash\_\-sector}, \/  uint8\_\-t {\em flash\_\-page}, \/  uint8\_\-t $\ast$ {\em mem\_\-ptr})}}
\label{m25p16_8h_a0b75960351bb943a848bd22a07208fe}


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

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em flash\_\-sector}]Sector number in the M25P16, range 0..31. \item[{\em flash\_\-page}]Page number in the sector. \item[{\em $\ast$mem\_\-ptr}]Pointer to the data location in memory\end{description}
\end{Desc}
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 \hyperlink{m25p16_8c_685b042fbdf45ec7f6f34982348e0851}{read\_\-write\_\-flash\_\-ram()} function instead. \hypertarget{m25p16_8h_aaeb96e65402cac033dfee993d07e758}{
\index{m25p16.h@{m25p16.h}!write\_\-ram\_\-status@{write\_\-ram\_\-status}}
\index{write\_\-ram\_\-status@{write\_\-ram\_\-status}!m25p16.h@{m25p16.h}}
\subsubsection[{write\_\-ram\_\-status}]{\setlength{\rightskip}{0pt plus 5cm}void write\_\-ram\_\-status (uint8\_\-t {\em status})}}
\label{m25p16_8h_aaeb96e65402cac033dfee993d07e758}


Write to the status register on the M25P16. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em status}]Value to write\end{description}
\end{Desc}
This function blocks until the bottom bit of the status register is clear = device ready. 