This repository has been archived on 2024-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
Solar-Panel/html/modbus_8c_source.html

240 lines
33 KiB
HTML
Raw Normal View History

2023-03-15 11:55:57 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Solar panel: modbus.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">Solar panel
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('modbus_8c_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="headertitle"><div class="title">modbus.c</div></div>
</div><!--header-->
<div class="contents">
<a href="modbus_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span> </div>
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno"> 2</span> </div>
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno"> 3</span><span class="preprocessor">#include &quot;<a class="code" href="modbus_8h.html">modbus.h</a>&quot;</span></div>
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno"> 4</span><span class="preprocessor">#include &quot;<a class="code" href="crc_8h.html">crc.h</a>&quot;</span></div>
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno"> 5</span> </div>
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno"> 6</span><span class="comment">// Modbus functions</span></div>
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno"><a class="line" href="modbus_8c.html#a860e48854b8e16a310dd29fe6e069561"> 7</a></span><span class="preprocessor">#define READ_INPUT_REGISTERS 0x04 </span></div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno"><a class="line" href="modbus_8c.html#a72629c87e1b18706ed17ee3dc768d5d1"> 8</a></span><span class="preprocessor">#define READ_HOLDING_REGISTERS 0x03 </span></div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno"><a class="line" href="modbus_8c.html#ae193fb8e7fb5dafe59b40642c13b4b42"> 9</a></span><span class="preprocessor">#define WRITE_SINGLE_REGISTER 0x06 </span></div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"> 10</span> </div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span><span class="comment">// Modbus data model</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"><a class="line" href="modbus_8c.html#a32ee4d57aa4ff7f7fce07fbe100dc0c2"> 12</a></span>uint8_t <a class="code hl_variable" href="modbus_8c.html#a32ee4d57aa4ff7f7fce07fbe100dc0c2">modbusAddress</a>;</div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"><a class="line" href="modbus_8c.html#af231936e7cd39b49156a2a178f3d54eb"> 13</a></span>uint16_t <a class="code hl_variable" href="modbus_8c.html#af231936e7cd39b49156a2a178f3d54eb">input_registers</a>[2];</div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"><a class="line" href="modbus_8c.html#a2aac17f17a0fbffad12e7ca46ed8ae0f"> 14</a></span>uint16_t <a class="code hl_variable" href="modbus_8c.html#a2aac17f17a0fbffad12e7ca46ed8ae0f">holding_registers</a>[2];</div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span> </div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span> </div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span><span class="comment">// Modbus error codes</span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"><a class="line" href="modbus_8c.html#a262addcd07ad5759dbeca3efe5d808d3"> 18</a></span><span class="preprocessor">#define ILLEGAL_FUNCTION 1</span></div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"><a class="line" href="modbus_8c.html#ad36357dad4ceb8b0ecb0f5f53eee1502"> 19</a></span><span class="preprocessor">#define ILLEGAL_DATA_ADDRESS 2</span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"><a class="line" href="modbus_8c.html#a2a9c40f66b96eb93a9dbb17d1f79443d"> 20</a></span><span class="preprocessor">#define ILLEGAL_DATA_VALUE 3</span></div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"><a class="line" href="modbus_8c.html#a92cb3f97527a2fbca9881dc0c14d98eb"> 21</a></span><span class="preprocessor">#define SLAVE_DEVICE_FAILURE 4</span></div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span> </div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"><a class="line" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46"> 27</a></span>uint8_t <a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[256];</div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"><a class="line" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b"> 28</a></span>uint8_t <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[256];</div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> </div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span><span class="comment">// Current position pointer for storing receive position</span></div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"><a class="line" href="modbus_8c.html#a9acb7baf86b62d19a199e672316e6294"> 31</a></span>uint8_t <a class="code hl_variable" href="modbus_8c.html#a9acb7baf86b62d19a199e672316e6294">recPtr</a> = 0;</div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> </div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"><a class="line" href="modbus_8c.html#add3e4a272cc65130d4e9f9c53caa61db"> 33</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="modbus_8c.html#add3e4a272cc65130d4e9f9c53caa61db">modbus_timer</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span> INTCONbits.TMR0IF = 0;</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span> <a class="code hl_variable" href="modbus_8c.html#a9acb7baf86b62d19a199e672316e6294">recPtr</a> = 0; </div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> <a class="code hl_function" href="tmr0_8c.html#afeaf0b9a17eeabda5d079bf63ed2b545">TMR0_StopTimer</a>();</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> <a class="code hl_function" href="modbus_8c.html#a6ae3279c3dcad4aa532eb07689f242e1">modbus_analyse_and_answer</a>();</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span>}</div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span><span class="keyword">extern</span> uint16_t <a class="code hl_function" href="modbus_8c.html#a104c0f284978c4cc8d34d36677a97e72">measure_voltage</a>();</div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"><a class="line" href="modbus_8c.html#a6ae3279c3dcad4aa532eb07689f242e1"> 40</a></span>uint8_t <a class="code hl_function" href="modbus_8c.html#a6ae3279c3dcad4aa532eb07689f242e1">modbus_analyse_and_answer</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span> <span class="comment">// TODO -&gt; complete the modbus analyse and answer</span></div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> uint16_t length = 0;</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> <span class="keywordflow">if</span>(<a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[0] == <a class="code hl_variable" href="modbus_8c.html#a32ee4d57aa4ff7f7fce07fbe100dc0c2">modbusAddress</a>){</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[0] = <a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[0]; <span class="comment">// Adress</span></div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[1] = <a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[1]; <span class="comment">// Function</span></div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> uint16_t adresseRegister = ((uint16_t)<a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[2] &lt;&lt; 8) | <a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[3];</div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> </div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> <span class="keywordflow">switch</span>(<a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[1]){ <span class="comment">// Check the function from rx buffer</span></div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span> <span class="keywordflow">case</span> <a class="code hl_define" href="modbus_8c.html#a860e48854b8e16a310dd29fe6e069561">READ_INPUT_REGISTERS</a>:</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span> length = ((uint16_t)<a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[4] &lt;&lt; 8) | <a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[5];</div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno"> 51</span> <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[2] = (uint8_t)(length*2); <span class="comment">// Data length</span></div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno"> 52</span> <span class="keywordflow">for</span>(uint16_t i = 0; i &lt; length; i++){ <span class="comment">// Data</span></div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[i*2+4] = <a class="code hl_variable" href="modbus_8c.html#af231936e7cd39b49156a2a178f3d54eb">input_registers</a>[adresseRegister+i];</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[i*2+3] = (<a class="code hl_variable" href="modbus_8c.html#af231936e7cd39b49156a2a178f3d54eb">input_registers</a>[adresseRegister+i] &gt;&gt; 8);</div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> }</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> length*=2;</div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> length+=3;</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> <span class="keywordflow">case</span> <a class="code hl_define" href="modbus_8c.html#a72629c87e1b18706ed17ee3dc768d5d1">READ_HOLDING_REGISTERS</a>:</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> length = ((uint16_t)<a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[4] &lt;&lt; 8) | <a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[5];</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[2] = (uint8_t)(length*2); <span class="comment">// Data length</span></div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> <span class="keywordflow">for</span>(uint16_t i = 0; i &lt; length; i++){ <span class="comment">// Data</span></div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[i*2+4] = <a class="code hl_variable" href="modbus_8c.html#a2aac17f17a0fbffad12e7ca46ed8ae0f">holding_registers</a>[adresseRegister+i];</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[i*2+3] = (<a class="code hl_variable" href="modbus_8c.html#a2aac17f17a0fbffad12e7ca46ed8ae0f">holding_registers</a>[adresseRegister+i] &gt;&gt; 8);</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> }</div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> length*=2;</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> length+=3;</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> <span class="keywordflow">case</span> <a class="code hl_define" href="modbus_8c.html#ae193fb8e7fb5dafe59b40642c13b4b42">WRITE_SINGLE_REGISTER</a>:</div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> <a class="code hl_variable" href="modbus_8c.html#a2aac17f17a0fbffad12e7ca46ed8ae0f">holding_registers</a>[adresseRegister] = ((uint16_t)<a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[4] &lt;&lt; 8) | <a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[5];</div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 2; i &lt;= 5; i++) {</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[i] = <a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[i];</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> length = i+1;</div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> }</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> }</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> </div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> }</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> </div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> <a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[0] = 0;</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> <a class="code hl_function" href="modbus_8c.html#af1b0553ef81d80e21233e23c3253ae61">modbus_send</a>(length);</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> </div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span>}</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> </div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"><a class="line" href="modbus_8c.html#aacb32a5aea357fae4e7fde574f95bfb9"> 85</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="modbus_8c.html#aacb32a5aea357fae4e7fde574f95bfb9">modbus_char_recvd</a>(<span class="keywordtype">void</span>)</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span>{</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> <a class="code hl_variable" href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a>[<a class="code hl_variable" href="modbus_8c.html#a9acb7baf86b62d19a199e672316e6294">recPtr</a>++] = RCREG1;</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> <a class="code hl_function" href="tmr0_8c.html#a61659c2dc0ff29595abe23b24cf81d14">TMR0_Reload</a>();</div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> <a class="code hl_function" href="tmr0_8c.html#a3e1b5e411afd874143ff241d08e52e07">TMR0_StartTimer</a>();</div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span>}</div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> </div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"><a class="line" href="modbus_8c.html#af1b0553ef81d80e21233e23c3253ae61"> 92</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="modbus_8c.html#af1b0553ef81d80e21233e23c3253ae61">modbus_send</a>(uint8_t length)</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span>{</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> </div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> uint16_t crc = <a class="code hl_function" href="crc_8c.html#a0fb245e3321a13b9170f7a948ed08b51">CRC16</a>(<a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>, length);</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> </div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[length] = crc;</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> <a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[length+1] = crc &gt;&gt; 8;</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> </div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</span> length += 2; <span class="comment">// add 2 CRC bytes for total size</span></div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span> </div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> <span class="comment">// For all the bytes to be transmitted</span></div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span> <span class="keywordflow">for</span> (uint8_t i = 0; i &lt; length; i++){</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span> <a class="code hl_function" href="eusart1_8c.html#a6acb88a121ac046bf5ae77f9a3521350">EUSART1_Write</a>(<a class="code hl_variable" href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a>[i]);</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> }</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span>}</div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span> </div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"><a class="line" href="modbus_8c.html#a67d9839b8e221bcb53bbbb2ba59ff618"> 108</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="modbus_8c.html#a67d9839b8e221bcb53bbbb2ba59ff618">modbus_init</a>(uint8_t address)</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span>{</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> <a class="code hl_variable" href="modbus_8c.html#a32ee4d57aa4ff7f7fce07fbe100dc0c2">modbusAddress</a> = address;</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span> <a class="code hl_variable" href="modbus_8c.html#a2aac17f17a0fbffad12e7ca46ed8ae0f">holding_registers</a>[1] = address;</div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span> <a class="code hl_function" href="eusart1_8c.html#a66a557ddf06eda003b454c56b5f6fa2b">EUSART1_SetRxInterruptHandler</a>(<a class="code hl_function" href="modbus_8c.html#aacb32a5aea357fae4e7fde574f95bfb9">modbus_char_recvd</a>);</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span> <a class="code hl_function" href="tmr0_8c.html#a1b6adc623040b0e791871a0f9652a67f">TMR0_SetInterruptHandler</a>(<a class="code hl_function" href="modbus_8c.html#add3e4a272cc65130d4e9f9c53caa61db">modbus_timer</a>);</div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span>}</div>
<div class="ttc" id="acrc_8c_html_a0fb245e3321a13b9170f7a948ed08b51"><div class="ttname"><a href="crc_8c.html#a0fb245e3321a13b9170f7a948ed08b51">CRC16</a></div><div class="ttdeci">uint16_t CRC16(const uint8_t *msg, uint16_t length)</div><div class="ttdef"><b>Definition:</b> <a href="crc_8c_source.html#l00048">crc.c:48</a></div></div>
<div class="ttc" id="acrc_8h_html"><div class="ttname"><a href="crc_8h.html">crc.h</a></div><div class="ttdoc">CRC calculation for Modbus.</div></div>
<div class="ttc" id="aeusart1_8c_html_a66a557ddf06eda003b454c56b5f6fa2b"><div class="ttname"><a href="eusart1_8c.html#a66a557ddf06eda003b454c56b5f6fa2b">EUSART1_SetRxInterruptHandler</a></div><div class="ttdeci">void EUSART1_SetRxInterruptHandler(void(*interruptHandler)(void))</div><div class="ttdef"><b>Definition:</b> <a href="eusart1_8c_source.html#l00234">eusart1.c:234</a></div></div>
<div class="ttc" id="aeusart1_8c_html_a6acb88a121ac046bf5ae77f9a3521350"><div class="ttname"><a href="eusart1_8c.html#a6acb88a121ac046bf5ae77f9a3521350">EUSART1_Write</a></div><div class="ttdeci">void EUSART1_Write(uint8_t txData)</div><div class="ttdef"><b>Definition:</b> <a href="eusart1_8c_source.html#l00162">eusart1.c:162</a></div></div>
<div class="ttc" id="amodbus_8c_html_a104c0f284978c4cc8d34d36677a97e72"><div class="ttname"><a href="modbus_8c.html#a104c0f284978c4cc8d34d36677a97e72">measure_voltage</a></div><div class="ttdeci">uint16_t measure_voltage()</div><div class="ttdef"><b>Definition:</b> <a href="measure_8c_source.html#l00037">measure.c:37</a></div></div>
<div class="ttc" id="amodbus_8c_html_a2aac17f17a0fbffad12e7ca46ed8ae0f"><div class="ttname"><a href="modbus_8c.html#a2aac17f17a0fbffad12e7ca46ed8ae0f">holding_registers</a></div><div class="ttdeci">uint16_t holding_registers[2]</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00014">modbus.c:14</a></div></div>
<div class="ttc" id="amodbus_8c_html_a32ee4d57aa4ff7f7fce07fbe100dc0c2"><div class="ttname"><a href="modbus_8c.html#a32ee4d57aa4ff7f7fce07fbe100dc0c2">modbusAddress</a></div><div class="ttdeci">uint8_t modbusAddress</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00012">modbus.c:12</a></div></div>
<div class="ttc" id="amodbus_8c_html_a579f15c7d6aeee8d684dce40e205c54b"><div class="ttname"><a href="modbus_8c.html#a579f15c7d6aeee8d684dce40e205c54b">tx_buf</a></div><div class="ttdeci">uint8_t tx_buf[256]</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00028">modbus.c:28</a></div></div>
<div class="ttc" id="amodbus_8c_html_a67d9839b8e221bcb53bbbb2ba59ff618"><div class="ttname"><a href="modbus_8c.html#a67d9839b8e221bcb53bbbb2ba59ff618">modbus_init</a></div><div class="ttdeci">void modbus_init(uint8_t address)</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00108">modbus.c:108</a></div></div>
<div class="ttc" id="amodbus_8c_html_a6ae3279c3dcad4aa532eb07689f242e1"><div class="ttname"><a href="modbus_8c.html#a6ae3279c3dcad4aa532eb07689f242e1">modbus_analyse_and_answer</a></div><div class="ttdeci">uint8_t modbus_analyse_and_answer(void)</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00040">modbus.c:40</a></div></div>
<div class="ttc" id="amodbus_8c_html_a72629c87e1b18706ed17ee3dc768d5d1"><div class="ttname"><a href="modbus_8c.html#a72629c87e1b18706ed17ee3dc768d5d1">READ_HOLDING_REGISTERS</a></div><div class="ttdeci">#define READ_HOLDING_REGISTERS</div><div class="ttdoc">Modbus function for read holding register = 03.</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00008">modbus.c:8</a></div></div>
<div class="ttc" id="amodbus_8c_html_a860e48854b8e16a310dd29fe6e069561"><div class="ttname"><a href="modbus_8c.html#a860e48854b8e16a310dd29fe6e069561">READ_INPUT_REGISTERS</a></div><div class="ttdeci">#define READ_INPUT_REGISTERS</div><div class="ttdoc">Modbus function for read input register = 04.</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00007">modbus.c:7</a></div></div>
<div class="ttc" id="amodbus_8c_html_a95463de2dabcd8671528bb72c7139e46"><div class="ttname"><a href="modbus_8c.html#a95463de2dabcd8671528bb72c7139e46">rx_buf</a></div><div class="ttdeci">uint8_t rx_buf[256]</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00027">modbus.c:27</a></div></div>
<div class="ttc" id="amodbus_8c_html_a9acb7baf86b62d19a199e672316e6294"><div class="ttname"><a href="modbus_8c.html#a9acb7baf86b62d19a199e672316e6294">recPtr</a></div><div class="ttdeci">uint8_t recPtr</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00031">modbus.c:31</a></div></div>
<div class="ttc" id="amodbus_8c_html_aacb32a5aea357fae4e7fde574f95bfb9"><div class="ttname"><a href="modbus_8c.html#aacb32a5aea357fae4e7fde574f95bfb9">modbus_char_recvd</a></div><div class="ttdeci">void modbus_char_recvd(void)</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00085">modbus.c:85</a></div></div>
<div class="ttc" id="amodbus_8c_html_add3e4a272cc65130d4e9f9c53caa61db"><div class="ttname"><a href="modbus_8c.html#add3e4a272cc65130d4e9f9c53caa61db">modbus_timer</a></div><div class="ttdeci">void modbus_timer(void)</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00033">modbus.c:33</a></div></div>
<div class="ttc" id="amodbus_8c_html_ae193fb8e7fb5dafe59b40642c13b4b42"><div class="ttname"><a href="modbus_8c.html#ae193fb8e7fb5dafe59b40642c13b4b42">WRITE_SINGLE_REGISTER</a></div><div class="ttdeci">#define WRITE_SINGLE_REGISTER</div><div class="ttdoc">Modbus function for write a single register = 06.</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00009">modbus.c:9</a></div></div>
<div class="ttc" id="amodbus_8c_html_af1b0553ef81d80e21233e23c3253ae61"><div class="ttname"><a href="modbus_8c.html#af1b0553ef81d80e21233e23c3253ae61">modbus_send</a></div><div class="ttdeci">void modbus_send(uint8_t length)</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00092">modbus.c:92</a></div></div>
<div class="ttc" id="amodbus_8c_html_af231936e7cd39b49156a2a178f3d54eb"><div class="ttname"><a href="modbus_8c.html#af231936e7cd39b49156a2a178f3d54eb">input_registers</a></div><div class="ttdeci">uint16_t input_registers[2]</div><div class="ttdef"><b>Definition:</b> <a href="modbus_8c_source.html#l00013">modbus.c:13</a></div></div>
<div class="ttc" id="amodbus_8h_html"><div class="ttname"><a href="modbus_8h.html">modbus.h</a></div><div class="ttdoc">Modbus serial library.</div></div>
<div class="ttc" id="atmr0_8c_html_a1b6adc623040b0e791871a0f9652a67f"><div class="ttname"><a href="tmr0_8c.html#a1b6adc623040b0e791871a0f9652a67f">TMR0_SetInterruptHandler</a></div><div class="ttdeci">void TMR0_SetInterruptHandler(void(*InterruptHandler)(void))</div><div class="ttdef"><b>Definition:</b> <a href="tmr0_8c_source.html#l00156">tmr0.c:156</a></div></div>
<div class="ttc" id="atmr0_8c_html_a3e1b5e411afd874143ff241d08e52e07"><div class="ttname"><a href="tmr0_8c.html#a3e1b5e411afd874143ff241d08e52e07">TMR0_StartTimer</a></div><div class="ttdeci">void TMR0_StartTimer(void)</div><div class="ttdef"><b>Definition:</b> <a href="tmr0_8c_source.html#l00097">tmr0.c:97</a></div></div>
<div class="ttc" id="atmr0_8c_html_a61659c2dc0ff29595abe23b24cf81d14"><div class="ttname"><a href="tmr0_8c.html#a61659c2dc0ff29595abe23b24cf81d14">TMR0_Reload</a></div><div class="ttdeci">void TMR0_Reload(void)</div><div class="ttdef"><b>Definition:</b> <a href="tmr0_8c_source.html#l00129">tmr0.c:129</a></div></div>
<div class="ttc" id="atmr0_8c_html_afeaf0b9a17eeabda5d079bf63ed2b545"><div class="ttname"><a href="tmr0_8c.html#afeaf0b9a17eeabda5d079bf63ed2b545">TMR0_StopTimer</a></div><div class="ttdeci">void TMR0_StopTimer(void)</div><div class="ttdef"><b>Definition:</b> <a href="tmr0_8c_source.html#l00103">tmr0.c:103</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="modbus_8c.html">modbus.c</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li>
</ul>
</div>
</body>
</html>