| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 6 | kaklik | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
||
| 3 | <title>Procyon AVRlib: spieeprom.c Source File</title> |
||
| 4 | <link href="dox.css" rel="stylesheet" type="text/css"> |
||
| 5 | </head><body> |
||
| 6 | <!-- Generated by Doxygen 1.4.2 --> |
||
| 7 | <div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> |
||
| 8 | <h1>spieeprom.c</h1><a href="spieeprom_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file spieeprom.c \brief Interface for standard SPI EEPROM memories. */</span> |
||
| 9 | 00002 <span class="comment">//*****************************************************************************</span> |
||
| 10 | 00003 <span class="comment">//</span> |
||
| 11 | 00004 <span class="comment">// File Name : 'spieeprom.c'</span> |
||
| 12 | 00005 <span class="comment">// Title : Interface for standard SPI EEPROM memories</span> |
||
| 13 | 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2004</span> |
||
| 14 | 00007 <span class="comment">// Created : 2004.10.07</span> |
||
| 15 | 00008 <span class="comment">// Revised : 2004.10.07</span> |
||
| 16 | 00009 <span class="comment">// Version : 0.1</span> |
||
| 17 | 00010 <span class="comment">// Target MCU : Atmel AVR series</span> |
||
| 18 | 00011 <span class="comment">// Editor Tabs : 4</span> |
||
| 19 | 00012 <span class="comment">//</span> |
||
| 20 | 00013 <span class="comment">// This code is distributed under the GNU Public License</span> |
||
| 21 | 00014 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span> |
||
| 22 | 00015 <span class="comment">//</span> |
||
| 23 | 00016 <span class="comment">//*****************************************************************************</span> |
||
| 24 | 00017 |
||
| 25 | 00018 <span class="preprocessor">#include <avr/io.h></span> |
||
| 26 | 00019 <span class="preprocessor">#include <avr/interrupt.h></span> |
||
| 27 | 00020 |
||
| 28 | 00021 <span class="preprocessor">#include "<a class="code" href="spi_8h.html">spi.h</a>"</span> |
||
| 29 | 00022 <span class="preprocessor">#include "<a class="code" href="spieeprom_8h.html">spieeprom.h</a>"</span> |
||
| 30 | 00023 |
||
| 31 | 00024 <span class="comment">// functions</span> |
||
| 32 | <a name="l00025"></a><a class="code" href="spieeprom_8h.html#a11">00025</a> <span class="keywordtype">void</span> <a class="code" href="spieeprom_8c.html#a0">spieepromInit</a>(<span class="keywordtype">void</span>) |
||
| 33 | 00026 { |
||
| 34 | 00027 <span class="comment">// although there is no code here</span> |
||
| 35 | 00028 <span class="comment">// don't forget to initialize the SPI interface itself</span> |
||
| 36 | 00029 <span class="comment">// sbi(DDRB, 0);</span> |
||
| 37 | 00030 } |
||
| 38 | 00031 |
||
| 39 | <a name="l00032"></a><a class="code" href="spieeprom_8h.html#a12">00032</a> u08 <a class="code" href="spieeprom_8c.html#a1">spieepromReadByte</a>(u32 memAddr) |
||
| 40 | 00033 { |
||
| 41 | 00034 u08 data; |
||
| 42 | 00035 <span class="comment">// cbi(PORTB,0);</span> |
||
| 43 | 00036 <span class="comment">// send command</span> |
||
| 44 | 00037 spiTransferByte(<a class="code" href="spieeprom_8h.html#a0">SPIEEPROM_CMD_READ</a>); |
||
| 45 | 00038 <span class="comment">// send address</span> |
||
| 46 | 00039 spiTransferByte(memAddr>>8); |
||
| 47 | 00040 spiTransferByte(memAddr&0x00FF); |
||
| 48 | 00041 <span class="comment">// read contents of memory address</span> |
||
| 49 | 00042 data = spiTransferByte(0xFF); |
||
| 50 | 00043 <span class="comment">// return data</span> |
||
| 51 | 00044 <span class="keywordflow">return</span> data; |
||
| 52 | 00045 <span class="comment">// sbi(PORTB,0);</span> |
||
| 53 | 00046 } |
||
| 54 | 00047 |
||
| 55 | <a name="l00048"></a><a class="code" href="spieeprom_8h.html#a13">00048</a> <span class="keywordtype">void</span> <a class="code" href="spieeprom_8c.html#a2">spieepromWriteByte</a>(u32 memAddr, u08 data) |
||
| 56 | 00049 { |
||
| 57 | 00050 <span class="comment">// wait for any previous write to complete</span> |
||
| 58 | 00051 <span class="keywordflow">while</span>(spieepromReadStatus() & <a class="code" href="spieeprom_8h.html#a6">SPIEEPROM_STATUS_WIP</a>); |
||
| 59 | 00052 |
||
| 60 | 00053 <span class="comment">// cbi(PORTB,0);</span> |
||
| 61 | 00054 <span class="comment">// send command</span> |
||
| 62 | 00055 spiTransferByte(<a class="code" href="spieeprom_8h.html#a1">SPIEEPROM_CMD_WRITE</a>); |
||
| 63 | 00056 <span class="comment">// send address</span> |
||
| 64 | 00057 spiTransferByte(memAddr>>8); |
||
| 65 | 00058 spiTransferByte(memAddr&0x00FF); |
||
| 66 | 00059 <span class="comment">// send data to be written</span> |
||
| 67 | 00060 spiTransferByte(data); |
||
| 68 | 00061 <span class="comment">// sbi(PORTB,0);</span> |
||
| 69 | 00062 } |
||
| 70 | 00063 |
||
| 71 | 00064 <span class="keywordtype">void</span> spieepromWriteEnable(<span class="keywordtype">void</span>) |
||
| 72 | 00065 { |
||
| 73 | 00066 <span class="comment">// cbi(PORTB,0);</span> |
||
| 74 | 00067 <span class="comment">// send command</span> |
||
| 75 | 00068 spiTransferByte(<a class="code" href="spieeprom_8h.html#a2">SPIEEPROM_CMD_WREN</a>); |
||
| 76 | 00069 <span class="comment">// sbi(PORTB,0);</span> |
||
| 77 | 00070 } |
||
| 78 | 00071 |
||
| 79 | 00072 <span class="keywordtype">void</span> spieepromWriteDisable(<span class="keywordtype">void</span>) |
||
| 80 | 00073 { |
||
| 81 | 00074 <span class="comment">// cbi(PORTB,0);</span> |
||
| 82 | 00075 <span class="comment">// send command</span> |
||
| 83 | 00076 spiTransferByte(<a class="code" href="spieeprom_8h.html#a3">SPIEEPROM_CMD_WRDI</a>); |
||
| 84 | 00077 <span class="comment">// sbi(PORTB,0);</span> |
||
| 85 | 00078 } |
||
| 86 | 00079 |
||
| 87 | 00080 u08 spieepromReadStatus(<span class="keywordtype">void</span>) |
||
| 88 | 00081 { |
||
| 89 | 00082 u08 status; |
||
| 90 | 00083 <span class="comment">// cbi(PORTB,0);</span> |
||
| 91 | 00084 <span class="comment">// send command</span> |
||
| 92 | 00085 spiTransferByte(<a class="code" href="spieeprom_8h.html#a4">SPIEEPROM_CMD_RDSR</a>); |
||
| 93 | 00086 <span class="comment">// get status register value</span> |
||
| 94 | 00087 status = spiTransferByte(0xFF); |
||
| 95 | 00088 <span class="comment">// sbi(PORTB,0);</span> |
||
| 96 | 00089 <span class="keywordflow">return</span> status; |
||
| 97 | 00090 } |
||
| 98 | </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by |
||
| 99 | <a href="http://www.doxygen.org/index.html"> |
||
| 100 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> |
||
| 101 | </body> |
||
| 102 | </html> |
Powered by WebSVN v2.8.3