SX127x
(→TX PKT) |
(→Node Addr) |
||
第41行: | 第41行: | ||
const uint8_t BROADCAST_0 = 0x00; | const uint8_t BROADCAST_0 = 0x00; | ||
− | writeRegister(REG_NODE_ADRS, | + | writeRegister(REG_NODE_ADRS, node_addr); |
writeRegister(REG_BROADCAST_ADRS, BROADCAST_0); | writeRegister(REG_BROADCAST_ADRS, BROADCAST_0); | ||
</source> | </source> |
2019年5月30日 (四) 10:45的版本
目录 |
1 TX PKT
struct pack { #ifdef W_NET_KEY uint8_t netkey[NET_KEY_LENGTH]; #endif uint8_t dst; uint8_t type; uint8_t src; uint8_t packnum; uint8_t length; uint8_t *data; uint8_t retry; /* retry number */ }; struct pack packet_sent; ...... ...... if (!_rawFormat) { writeRegister(REG_FIFO, packet_sent.dst); // Writing the destination in FIFO writeRegister(REG_FIFO, packet_sent.type); // Writing the packet type in FIFO writeRegister(REG_FIFO, packet_sent.src); // Writing the source in FIFO writeRegister(REG_FIFO, packet_sent.packnum); // Writing the packet number in FIFO }
2 Node Addr
#define REG_NODE_ADRS 0x33 #define REG_BROADCAST_ADRS 0x34 const uint8_t BROADCAST_0 = 0x00; writeRegister(REG_NODE_ADRS, node_addr); writeRegister(REG_BROADCAST_ADRS, BROADCAST_0);
3 CAD
Channel Activity Detection. It's designed to detect a LoRa preamble on the radio channel with the best possible power efficiency.
Once in CAD mode, the SX127x will perform a very quick scan of the band to detect a LoRa packet preamble.
During CAD, the following operation take place:
- The PLL locks
- The radio receiver captures LoRa preamble symbol of data from the channel. The radio current consumption during that phase is approximately 10mA.
- The radio receiver and the PLL turn off and the modem digital processing starts.
- The modem searches for a correlation between the Radio captured samples and the ideal preamble waveform. This correlation process takes a little bit less than a symbol period toperform. The radio current consumption during that phase is greatly reduced.
- Once the calculation is finished the modem generates the CadDone interrupt. If the correlation was successful, the CadDetected is generated simultaneously.
- The chip goes back to stand-by mode.
- If a preamble was detected, clear the interrupt, then initiate the reception by putting the radio in RX single mode or RX continuous mode.
The typical CAD detection time:
SymbolTime = (2^SF + 32) / BW seconds
Refer to: Reading channel RSSI during a CAD
4 RSSI
Received Signal Strength Indication,接收信号强度指示
Antenna Diversity,天线分集
The RSSI information is available during CAD and there is no need to leave the receiver on for some additional time
During a CAD, The device is effectively in Reception mode for the duration of one LoRa symbol. It is therefore possible to read the RSSI of the signal present within the LoRa bandwidth.
While in reception, the RSSI is sample every 8uS and is asymptotically analyzed. This means that the RSSI value is being calculated along the length of the symbol duration and is directly related to the number of point previously analyzed.
symbolTime = (pow((float)2, (float)LORA_SPREADING_FACTOR)) + 32) / 125000; // SF7 and BW = 125 KHz symbolTime = symbolTime * 1000000; // symbol Time is in us while( 1 ) { t.reset( ); // Reset the Timer Radio.StartCad( ); // Set the device into CAD mode t.start( ); // Start the Timer while( t.read_us ( ) < 240 ); // 240us are needed for the device to go into CAD Mode from Sleep Mode while( t.read_us ( ) < symbolTime + 240); // We wait for Symbol Time and 240 us to be at the very end of // the symbol duration rssi[i++] = Radio.GetRssi( MODEM_LORA ); // We can now read the RSSI t.stop( ); // Stop the Timer while( State != CAD_DONE ); // Wait for the end of the CAD process }
5 Preamble
LoRa 数据包前导码,用于接收机辩识 rx data flow。内容固定,长度可选。
默认 12 个 symbol(Bytes?), 0x8 (RegPreambleLsb) + 4
可写 RegPreambleMsb 和 RegPreambleLsb 这两个寄存器,将其改为 6 +4 ~ 65535 +4
10 symbol 的短前导码,通信够用但具有更短的接收周期。。。
当前系统一般皆适用 12 (4 + 8) 的长度:
...... ^$Get Preamble Length: state 0 ^$Preamble Length: 8 ......
6 Header
Explicit Header & Implicit Header
可通过寄存器 RegModemConfig1 内的位 ImplicitHeaderModeOn 来控制
Explicit Header:
Reset 默认的模式。其能提供的信息:
- Payload 长度
- The forward error correction code rate
- The presence of an optional 16-bits CRC for the payload
The head is transmitted with maximum error correction code (4/8). It also has its own CRC to allow the receiver to discard invalid headers.
Implicit Header:
Header is removed from the LoRa Packet.
Payload, Coding Rate and CRC presence are fixed.
Be advantageous to reduce transmission time
7 CRC
RegPayloadCrcOn: RegModemConfig2[2:2]
- 0 ---> CRC disable
- 1 ---> CRC enable
In Implicit Header Mode: must be set on Tx and Rx side
In Explicit Header Mode: on the Tx side alone (recovered from the header in Rx side)
Explicit Header Mode Checking process:
Rx 用户负责检查 CrcOnPayload (RegHopChannel[6:6], CRC information extracted from the rx packet header)
如果 CrcOnPayload == 1,需要检查 IRQ 标志位 PayloadCrcError,以确保没有 CRC 错误
Implicit Header Mode 则直接去检查 IRQ 标志位 PayloadCrcError,以确保没有 CRC 错误
8 Reference