【NUCLEO-WL55JC2测评6】 LoRa点对点通信
<div class='showpostmsg'> 本帖最后由 nich20xx 于 2020-7-9 09:09 编辑<p><meta name="source" content="lake" /></p>
<p data-lake-id="63d3abf5d3938a3c0f2bf1fbcda60424"> </p>
<h1 data-lake-id="9a2fbc490f643311ff3ad834df8274c5" id="2vHlU">1 前言</h1>
<p data-lake-id="5577e00ceb57e5bdaf8deca207360cc1">LoRa调制方式是STM32WL的核心功能之一。</p>
<p data-lake-id="70e6dc3c861610d1c17d2cef1bc74de0">NUCLEO-WL55JC2的LoRa IP采用的是SX126x,因此LoRa部分的软件操作,跟单芯片SX126x软件访问方式有些相似,ST提供了类似SPI方式的API接口。</p>
<p data-lake-id="44a145a58c66e12a39aab3b8f8e98fb8">本文主要内容提要:</p>
<ul data-lake-id="5a5aa7d33c7a551b0fd7fafe628f36be" lake-indent="1">
<li>LoRa点对点单向、双向通信</li>
<li>互通性验证
<ul>
<li>NUCLEO-WL55JC2、SX126x 模块、SX1278模块 互联互通</li>
</ul>
</li>
</ul>
<blockquote>
<p><u>lora-radio-driver代码github仓库</u></p>
<p><u>https://github.com/Forest-Rain/lora-radio-driver</u></p>
</blockquote>
<h1 data-lake-id="8f40e0e44de94b7888cb80e6382e0f77" id="VGKEa">2 LoRa通信</h1>
<h2 data-lake-id="00215b484a8582c9f847bca755935916" id="GsMuU">2.1 LoRa数据帧格式</h2>
<p data-lake-id="5742600967335e5f4c63ad92a14d032b">LoRa数据帧支持显性格式(Explicit header mode packet)与隐形格式( Implicit header mode packet )(no header)。</p>
<p data-lake-id="c2755a2aa9748d61af6b8ecef028c147"></p>
<h2 data-lake-id="8b0b1f3705144a46b957e57246ef8ffd" id="OhLRx">2.2 LoRa通信参数</h2>
<p data-lake-id="c087ef8b7208c206b4fdfce7eb14a750">LoRa通信参数主要有:</p>
<ul data-lake-id="6e2b8d3731b17af7b79191f700b15b82" lake-indent="1">
<li>spreading factor (SF)</li>
<li>modulation bandwidth (BW)</li>
<li>error coding rate (CR)</li>
<li>low data rate optimization (LDRO)
<ul>
<li>对于高SF或者低BW,同时长数据包,LDRO被使能,以便接收机更好正确解调LoRa信号</li>
</ul>
</li>
</ul>
<p data-lake-id="e0922ebd1eb1b16af143b64b817bfb50">根据实际应用来选择合适的LoRa通信参数,以在链路预算、抗干扰、带宽、标称速率等之间获得平衡。</p>
<p data-lake-id="de09fb097be9be06c27336ef56f3e0a1"></p>
<h2 data-lake-id="8ac70d17d958f2516a420b370dad5f9d" id="ejGR1">2.3 STM32WL LoRa驱动</h2>
<p></p>
<h1 data-lake-id="47ff5621897db9b079cba2c43caf96eb" id="HkVOo">3 LoRa点对点通信</h1>
<p data-lake-id="2e4e8a7e805fdd950dd79df1432589bf">一次完整的双向通信过程如下:</p>
<ol data-lake-id="2d7ebe843d878868d120ee977c658b2e" lake-indent="0" start="1">
<li data-lake-id="69cd59b42b9a9424624c4ca9fde73a5e">主机发起通信,发送一个数据包完成后,立即进入接收</li>
<li data-lake-id="e07c6da0423789052a46fd8a0e10f730">从机默认一直处于接收状态,接收到主机的数据后,回传接收到的数据包</li>
<li data-lake-id="f4563be1debc78a2e0b005118ecd4d63">主机端接收到应答数据后,判断接收数据包内容是否正确</li>
<li data-lake-id="9e44cd708061ad1b478beb300f00d6f1">同时使用一个设备只接收,用作监听设备,用于监听与分析主机与从机发送的数据。</li>
</ol>
<p></p>
<p data-lake-id="4f55880f63b78d1117f2b40c59b97c0e">点对点双向通信流程</p>
<h2 data-lake-id="4fee2e27eee98e39456e4fa3830c7876" id="1Hcdl">3.1 通信测试</h2>
<h3 data-lake-id="4175a34beebc7955dbdab22425e25277" id="QmIXX">3.1.1 LoRa通信参数配置</h3>
<p data-lake-id="151d4d5905d6b1531c5e57a5bed9b8f1"></p>
<h4 data-lake-id="348fe4f24fcc33312d7259dca9dc129e" id="c2zlm">3.1.1.1 射频初始化</h4>
<pre>
<code class="language-cpp">#define TX_OUTPUT_POWER 14 // dBm
#define LORA_BANDWIDTH 0 // [0: 125 kHz,
//1: 250 kHz,
//2: 500 kHz,
//3: Reserved]
#define LORA_SPREADING_FACTOR 7 //
#define LORA_CODINGRATE 1 // [1: 4/5,
//2: 4/6,
//3: 4/7,
//4: 4/8]
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
{
// ...
Radio.SetChannel( lora_radio_test_paras.frequency );
Radio.SetTxConfig( MODEM_LORA, lora_radio_test_paras.txpower, 0, lora_radio_test_paras.bw,
lora_radio_test_paras.sf, lora_radio_test_paras.cr,
LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );
Radio.SetRxConfig( MODEM_LORA, lora_radio_test_paras.bw, lora_radio_test_paras.sf,
lora_radio_test_paras.cr, 0, LORA_PREAMBLE_LENGTH,
LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
0, true, 0, 0, LORA_IQ_INVERSION_ON, true );
}</code></pre>
<h4 data-lake-id="e90acf1208a41d286ab6a04f19cd13da" id="vO6yO">3.1.1.2 生成空口测试包</h4>
<pre>
<code class="language-cpp">void send_ping_packet(uint32_t src_addr,uint32_t dst_addr,uint8_t len)
{
tx_seq_cnt++;
tx_timestamp = TimerGetCurrentTime();
// Send the next PING frame
uint8_t index = 0;
// header
Buffer = 0x00; // echo cmd
Buffer = src_addr & 0xFF;
Buffer = src_addr >> 8;
Buffer = src_addr >> 16;
Buffer = src_addr >> 24;
Buffer = dst_addr & 0xFF;
Buffer = dst_addr >> 8;
Buffer = dst_addr >> 16;
Buffer = dst_addr >> 24;
Buffer = tx_seq_cnt & 0xFF;
Buffer = tx_seq_cnt >> 8;
Buffer = tx_seq_cnt >> 16;
Buffer = tx_seq_cnt >> 24;
// data
Buffer = 'P';
Buffer = 'I';
Buffer = 'N';
Buffer = 'G';
// 00,01,02...
for( uint8_t i = 0; i < len - index ; i++)
{
Buffer = i;
}
rt_thread_mdelay(1);
Radio.Send( Buffer, len );
}</code></pre>
<h2 data-lake-id="cbe1c88227cfd405c842aec82db32cc3" id="TXBHb">3.2 通信测试结果</h2>
<h3 data-lake-id="b1a9d6a924366619114c832e253c6737" id="ny8Bs">3.2.1 单向通信</h3>
<ul data-lake-id="5fd7f7ce1786ad1be42794d7c7f0b821" lake-indent="0">
<li data-lake-id="ebf53c0124a3a4d196e32716c87c9683">测试目的</li>
</ul>
<p data-lake-id="ae39ea48d9480ee253d9f970b7be1fa4">验证NUCLEO-WL32JC2单向LoRa通信</p>
<ul data-lake-id="4b866afddff6c40a1dd9707d78ffee40" lake-indent="0">
<li data-lake-id="2880549b6b89a8092949e31d4aab5e82">测试设备:
<ul>
<li data-lake-id="2880549b6b89a8092949e31d4aab5e82">1个NUCLEO-WL32JC2</li>
<li data-lake-id="2880549b6b89a8092949e31d4aab5e82">1个SX1268模块</li>
</ul>
</li>
<li data-lake-id="ecd9e7686e7f977a61e85372e5ec0277">测试步骤</li>
</ul>
<p data-lake-id="eee59b6784fc7ec3dfac546f1d90983a">使用NUCLEO-WL32JC2发送,SX1268模块接收</p>
<ul data-lake-id="67b45c4aa54fc33264151281991a1757" lake-indent="1">
<li>1个NUCLEO-WL32JC2为发送端 ( lora ping -m)</li>
<li>1个SX1268模块只接收(监听)( lora ping -s)</li>
</ul>
<p data-lake-id="b870ab553f42f6cf8dcba5851ed996c2"></p>
<p data-lake-id="d81191c1744937b4c47267f2e54e85a3">STM32WL发送,SX1268模块接收</p>
<h3 data-lake-id="4c95edfa956df7e36b24adf66735bc57" id="IpSys">3.2.2 双向通信</h3>
<ul data-lake-id="f283df96338bea750e26054e4d6dfe8c" lake-indent="0">
<li data-lake-id="a4558ac97ce5ae0b7a61b47e06a15b8d">测试目的
<ul>
<li data-lake-id="a4558ac97ce5ae0b7a61b47e06a15b8d">验证NUCLEO-WL32JC2的双向通信</li>
</ul>
</li>
</ul>
<ul data-lake-id="0c1a129e47d4a955f24fbec6ce20bb61" lake-indent="1">
<li data-lake-id="cda15abad6bc4ec117d0162922d19257">测试设备:
<ul>
<li data-lake-id="cda15abad6bc4ec117d0162922d19257">2个NUCLEO-WL32JC2</li>
</ul>
</li>
<li data-lake-id="6eb5e65942388953f376fee931f4aa56">测试步骤</li>
</ul>
<ol data-lake-id="d1ec09e5754af428794290100585f3e8" lake-indent="0" start="1">
<li data-lake-id="5aa7de9fe0ab47b1aaa88470a37f743b">主机输入 lora ping -m,主机测试日志如下</li>
</ol>
<p data-lake-id="387f8f527187185894bf38733dcf7b41"></p>
<p data-lake-id="1491c1596d8af40b7917f7d7097e77af">主机STM32WL发送,并接收应答</p>
<ol data-lake-id="ccfb0f218f7f2bcec2241cdc83f05540" lake-indent="0" start="2">
<li data-lake-id="1f45075c13afb14dbe66949231894a3d">从机输入 lora ping -s,-s也可以缺省,从机测试日志如下</li>
</ol>
<p data-lake-id="f97a51764a84a60061f3d831682b4cd4"></p>
<p data-lake-id="d442e9e31b3f16123a2fe944b250db0d">从机SX1268模块侧接收数据,然后回传</p>
<h3 data-lake-id="44f801a700ea52b3b65c35e1119aed2c" id="krYWa">3.2.3 互通性</h3>
<p data-lake-id="3f797edfafd167a43b20995f66f08e96">测试目的:</p>
<p data-lake-id="74e2f0891e519f00b05b2f2403e10b53">验证STM32WL与SX126X、SX127X模块之间的互连互通。</p>
<p data-lake-id="af8436bd4229510a093fe69fe8b83695">测试设备:</p>
<ul data-lake-id="2b77e7e90bfc1b0d0f2443243955da1d" lake-indent="1">
<li>1个NUCLEO-WL32JC2做主机 ( lora ping -m)</li>
<li>1个SX1268模块做从机 ( lora ping -s)</li>
<li>1个NUCLEO-WL32JC2只接收(监听)( lora rx)</li>
<li>1个SX1278模块只接收(监听)( lora rx)</li>
</ul>
<p data-lake-id="c81c1802630e1a622093d610c62062c7"><meta name="source" content="lake" /></p>
<p data-lake-id="5bd06d21867aaa914f6d094ea8342800"></p>
<p data-lake-id="5bd06d21867aaa914f6d094ea8342800">互通性测试(STM32WL <-> SX1268模块,STM32WL、SX1278模块监听)</p>
<p data-lake-id="1a81eeffab69d886ec343df913c101e1"><meta name="source" content="lake" /></p>
<h1 data-lake-id="1b57598251ac48b82486c11660616ef0" id="wpMJj">4 参考</h1>
<ul data-lake-id="4cf4e42e1f4cf231cc9b8aa3ed9febe7" lake-indent="0">
<li data-lake-id="ce3646c63395b2c4df8826b48c832ab3">RM0461 STM32WLEx advanced Arm-based 32-bit MCUs with sub-GHz radio solution Rev01.pdf</li>
<li data-lake-id="d2e6c8375ddec6511e45dfaf5aa1602c">STM32Cube_FW_WL_V0.4.0</li>
<li data-lake-id="bbe9167947b429cfc41db8033c380ef0">基于RT-Thread的LoRa Radio Driver软件包
<ul>
<li data-lake-id="bbe9167947b429cfc41db8033c380ef0"><a href="https://github.com/Forest-Rain/lora-radio-driver" target="_blank">https://github.com/Forest-Rain/lora-radio-driver</a></li>
</ul>
</li>
</ul>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>这代码,一看就头大,要玩转这块板不容易,幸好没申请</p>
donatello1996 发表于 2020-7-9 14:14
这代码,一看就头大,要玩转这块板不容易,幸好没申请
<p>搞板子看代码还是必经之路</p>
<p> </p>
<p>我现在买了一个透传模块,以为它可以监听WL55JC2的只要参数设置一直,可买来后透传产家不提供SX1268的配置参数。现在变成进退两难</p>
<p> </p>
页:
[1]