📄 usart__example_8c.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>AVR321000 Communication with the AVR32 USART: usart_example.c File Reference</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.1 --><div class="tabs"> <ul> <li><a href="main.html"><span>Main Page</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li id="current"><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul></div><div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul></div><h1>usart_example.c File Reference</h1><hr><a name="_details"></a><h2>Detailed Description</h2>Example on usage of the AVR32 USART device library. <p>This file contains an example on how to use the AVR32 USART driver. It initializes the USART and puts out a string. See the documentation or comments within the file for settings and more info<p><ul><li>Compiler: IAR EWAAVR32 and GNU GCC for AVR32</li><li>Supported devices: All AVR32 devices with a USART module can be used.</li><li>AppNote: AVR32100 - Communication with the AVR32 USART</li></ul><p><dl class="author" compact><dt><b>Author:</b></dt><dd>Atmel Corporation: <a href="http://www.atmel.com">http://www.atmel.com</a> <br> Support email: <a href="mailto:avr32@atmel.com">avr32@atmel.com</a></dd></dl>$Name$ <dl class="rcs" compact><dt><b>Revision</b></dt><dd>67 </dd></dl>$RCSfile$ <dl class="rcs" compact><dt><b>Date</b></dt><dd>2006-05-10 15:00:07 +0200 (Wed, 10 May 2006) </dd></dl><p>Definition in file <a class="el" href="usart__example_8c-source.html">usart_example.c</a>.<p><code>#include "<a class="el" href="usart_8h-source.html">usart.h</a>"</code><br><p>Include dependency graph for usart_example.c:<p><center><img src="usart__example_8c__incl.png" border="0" usemap="#usart_example.c_map" alt=""></center><map name="usart_example.c_map"><area href="usart_8h.html" shape="rect" coords="187,6,256,30" alt=""></map><p><a href="usart__example_8c-source.html">Go to the source code of this file.</a><table border="0" cellpadding="0" cellspacing="0"><tr><td></td></tr><tr><td colspan="2"><br><h2>Defines</h2></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="usart__example_8c.html#6d58f9ac447476b4e084d7ca383f5183">FAILURE</a> -1;</td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="usart__example_8c.html#a90cac659d18e8ef6294c7ae337f6b58">SUCCESS</a> 0;</td></tr><tr><td colspan="2"><br><h2>Typedefs</h2></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">typedef unsigned char </td><td class="memItemRight" valign="bottom"><a class="el" href="usart__example_8c.html#8a26ea9b2ab943a38ada2d6ca9282231">avr32_piomap_t</a> [][2]</td></tr><tr><td colspan="2"><br><h2>Functions</h2></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="usart__example_8c.html#840291bc02cba5474a4cb46a9b9566fe">main</a> (void)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Sets up the USART and print's a string. <a href="#840291bc02cba5474a4cb46a9b9566fe"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="usart__example_8c.html#0789f45a4ff69e0f650c2d3e2fdf35bb">pio_enable_module</a> (<a class="el" href="usart__example_8c.html#8a26ea9b2ab943a38ada2d6ca9282231">avr32_piomap_t</a> piomap, unsigned int size)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Set the pins under module control. <a href="#0789f45a4ff69e0f650c2d3e2fdf35bb"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="usart__example_8c.html#2929a2158663c710a90f2d760007397a">print</a> (volatile struct avr32_usart_t *usart, char *str)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Print a string of characters to an usart. <a href="#2929a2158663c710a90f2d760007397a"></a><br></td></tr></table><hr><h2>Define Documentation</h2><a class="anchor" name="6d58f9ac447476b4e084d7ca383f5183"></a><!-- doxytag: member="usart_example.c::FAILURE" ref="6d58f9ac447476b4e084d7ca383f5183" args="" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname">#define FAILURE -1; </td> </tr> </table></div><div class="memdoc"><p><p>Definition at line <a class="el" href="usart__example_8c-source.html#l00062">62</a> of file <a class="el" href="usart__example_8c-source.html">usart_example.c</a>.<p>Referenced by <a class="el" href="usart__example_8c-source.html#l00150">pio_enable_module()</a>.</div></div><p><a class="anchor" name="a90cac659d18e8ef6294c7ae337f6b58"></a><!-- doxytag: member="usart_example.c::SUCCESS" ref="a90cac659d18e8ef6294c7ae337f6b58" args="" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname">#define SUCCESS 0; </td> </tr> </table></div><div class="memdoc"><p><p>Definition at line <a class="el" href="usart__example_8c-source.html#l00061">61</a> of file <a class="el" href="usart__example_8c-source.html">usart_example.c</a>.<p>Referenced by <a class="el" href="usart__example_8c-source.html#l00096">main()</a>.</div></div><p><hr><h2>Typedef Documentation</h2><a class="anchor" name="8a26ea9b2ab943a38ada2d6ca9282231"></a><!-- doxytag: member="usart_example.c::avr32_piomap_t" ref="8a26ea9b2ab943a38ada2d6ca9282231" args="[][2]" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname">typedef unsigned char <a class="el" href="usart__example_8c.html#8a26ea9b2ab943a38ada2d6ca9282231">avr32_piomap_t</a>[][2] </td> </tr> </table></div><div class="memdoc"><p><p>Definition at line <a class="el" href="usart__example_8c-source.html#l00064">64</a> of file <a class="el" href="usart__example_8c-source.html">usart_example.c</a>.</div></div><p><hr><h2>Function Documentation</h2><a class="anchor" name="840291bc02cba5474a4cb46a9b9566fe"></a><!-- doxytag: member="usart_example.c::main" ref="840291bc02cba5474a4cb46a9b9566fe" args="(void)" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname">int main </td> <td>(</td> <td class="paramtype">void </td> <td class="paramname"> </td> <td> ) </td> <td width="100%"></td> </tr> </table></div><div class="memdoc"><p>Sets up the USART and print's a string. <p><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em></em> </td><td></td></tr> </table></dl><dl class="return" compact><dt><b>Returns:</b></dt><dd>; </dd></dl><p>Definition at line <a class="el" href="usart__example_8c-source.html#l00096">96</a> of file <a class="el" href="usart__example_8c-source.html">usart_example.c</a>.<p>References <a class="el" href="usart_8h-source.html#l00077">usart_options_t::baudrate</a>, <a class="el" href="usart_8h-source.html#l00104">usart_options_t::channelmode</a>, <a class="el" href="usart_8h-source.html#l00082">usart_options_t::charlength</a>, <a class="el" href="usart_8h-source.html#l00089">usart_options_t::paritytype</a>, <a class="el" href="usart__example_8c-source.html#l00150">pio_enable_module()</a>, <a class="el" href="usart__example_8c-source.html#l00134">print()</a>, <a class="el" href="usart_8h-source.html#l00097">usart_options_t::stopbits</a>, <a class="el" href="usart__example_8c-source.html#l00061">SUCCESS</a>, <a class="el" href="usart_8h-source.html#l00316">USART_1_STOPBIT</a>, <a class="el" href="usart_8c-source.html#l00152">usart_init_rs232()</a>, <a class="el" href="usart_8h-source.html#l00285">USART_NO_PARITY</a>, and <a class="el" href="usart_8h-source.html#l00307">USART_NORMAL_CHMODE</a>.<div class="fragment"><pre class="fragment"><a name="l00097"></a>00097 {<a name="l00098"></a>00098 <span class="keywordtype">int</span> cpu_hz = 20000000;<a name="l00099"></a>00099 <span class="keyword">struct </span><a class="code" href="structusart__options__t.html">usart_options_t</a> opt;<a name="l00100"></a>00100 <a name="l00101"></a>00101 <span class="keyword">volatile</span> <span class="keyword">struct </span>avr32_usart_t *usart = &AVR32_USART1;<a name="l00102"></a>00102 <a name="l00103"></a>00103 <a class="code" href="usart__example_8c.html#8a26ea9b2ab943a38ada2d6ca9282231">avr32_piomap_t</a> usart_piomap = { \<a name="l00104"></a>00104 {AVR32_USART1_RXD_0_PIN, AVR32_USART1_RXD_0_FUNCTION}, \<a name="l00105"></a>00105 {AVR32_USART1_TXD_0_PIN, AVR32_USART1_TXD_0_FUNCTION} \<a name="l00106"></a>00106 };<a name="l00107"></a>00107 <a name="l00108"></a>00108 <span class="comment">// Set options for the USART</span><a name="l00109"></a>00109 opt.<a class="code" href="structusart__options__t.html#276ad428776a25b8247762bd2c82b35b">baudrate</a> = 115200;<a name="l00110"></a>00110 opt.<a class="code" href="structusart__options__t.html#a6b77cc05829d2e70ee7f96194c6ce23">charlength</a> = 8;<a name="l00111"></a>00111 opt.<a class="code" href="structusart__options__t.html#85401f7a6f516a5883adc0538dc27f8e">paritytype</a> = <a class="code" href="usart_8h.html#0b656451a78c0f602ee8855d52c719a8">USART_NO_PARITY</a>;<a name="l00112"></a>00112 opt.<a class="code" href="structusart__options__t.html#433a6ede2186d42b4cf19ef4b370cd61">stopbits</a> = <a class="code" href="usart_8h.html#f2d819c8836b2d7838ab501d36458969">USART_1_STOPBIT</a>;<a name="l00113"></a>00113 opt.<a class="code" href="structusart__options__t.html#0dc365b8779891743180e9b69116f5ea">channelmode</a> = <a class="code" href="usart_8h.html#0bd9f61e5232af833543eac9419c2d70">USART_NORMAL_CHMODE</a>;<a name="l00114"></a>00114 <a name="l00115"></a>00115 <span class="comment">// Initialize it in RS232 mode</span><a name="l00116"></a>00116 <a class="code" href="usart_8c.html#48c8d76fc9fdde84b94a6e09184a6446">usart_init_rs232</a>(usart, &opt, cpu_hz);<a name="l00117"></a>00117 <a name="l00118"></a>00118 <span class="comment">// Setup pio for USART</span><a name="l00119"></a>00119 <a class="code" href="usart__example_8c.html#0789f45a4ff69e0f650c2d3e2fdf35bb">pio_enable_module</a>(usart_piomap, 2);<a name="l00120"></a>00120 <a name="l00121"></a>00121 <a class="code" href="usart__example_8c.html#2929a2158663c710a90f2d760007397a">print</a>(usart, <span class="stringliteral">"This is AVR32 saying hello from the STK1000!\n"</span>);<a name="l00122"></a>00122 <a name="l00123"></a>00123 <span class="keywordflow">return</span> <a class="code" href="usart__example_8c.html#a90cac659d18e8ef6294c7ae337f6b58">SUCCESS</a>;<a name="l00124"></a>00124 }</pre></div>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -