mirror of
				https://github.com/markqvist/RNode_Firmware.git
				synced 2025-10-31 06:37:04 -04:00 
			
		
		
		
	Reworked DCD methods for SX1276 and SX1280
This commit is contained in:
		
							parent
							
								
									a796e56dd9
								
							
						
					
					
						commit
						58f6a3d6a3
					
				
					 4 changed files with 36 additions and 16 deletions
				
			
		|  | @ -86,7 +86,6 @@ uint8_t ISR_VECT sx127x::readRegister(uint8_t address) { return singleTransfer(a | |||
| void sx127x::writeRegister(uint8_t address, uint8_t value) { singleTransfer(address | 0x80, value); } | ||||
| void sx127x::standby() { writeRegister(REG_OP_MODE_7X, MODE_LONG_RANGE_MODE_7X | MODE_STDBY_7X); } | ||||
| void sx127x::sleep() { writeRegister(REG_OP_MODE_7X, MODE_LONG_RANGE_MODE_7X | MODE_SLEEP_7X); } | ||||
| uint8_t sx127x::modemStatus() { return readRegister(REG_MODEM_STAT_7X); } | ||||
| void sx127x::setSyncWord(uint8_t sw) { writeRegister(REG_SYNC_WORD_7X, sw); } | ||||
| void sx127x::enableCrc() { writeRegister(REG_MODEM_CONFIG_2_7X, readRegister(REG_MODEM_CONFIG_2_7X) | 0x04); } | ||||
| void sx127x::disableCrc() { writeRegister(REG_MODEM_CONFIG_2_7X, readRegister(REG_MODEM_CONFIG_2_7X) & 0xfb); } | ||||
|  | @ -195,6 +194,14 @@ int sx127x::endPacket() { | |||
|   return 1; | ||||
| } | ||||
| 
 | ||||
| bool sx127x::dcd() { | ||||
|   bool carrier_detected = false; | ||||
|   uint8_t status = readRegister(REG_MODEM_STAT_7X); | ||||
|   if ((status & SIG_DETECT) == SIG_DETECT) { carrier_detected = true; } | ||||
|   if ((status & SIG_SYNCED) == SIG_SYNCED) { carrier_detected = true; } | ||||
|   return carrier_detected; | ||||
| } | ||||
| 
 | ||||
| uint8_t sx127x::currentRssiRaw() { | ||||
|     uint8_t rssi = readRegister(REG_RSSI_VALUE_7X); | ||||
|     return rssi; | ||||
|  |  | |||
							
								
								
									
										7
									
								
								sx127x.h
									
										
									
									
									
								
							
							
						
						
									
										7
									
								
								sx127x.h
									
										
									
									
									
								
							|  | @ -18,6 +18,11 @@ | |||
| 
 | ||||
| #define RSSI_OFFSET 157 | ||||
| 
 | ||||
| // Modem status flags
 | ||||
| #define SIG_DETECT 0x01 | ||||
| #define SIG_SYNCED 0x02 | ||||
| #define RX_ONGOING 0x04 | ||||
| 
 | ||||
| class sx127x : public Stream { | ||||
| public: | ||||
|   sx127x(); | ||||
|  | @ -65,7 +70,7 @@ public: | |||
|   void setCodingRate4(int denominator); | ||||
|   void setPreambleLength(long preamble_symbols); | ||||
|   void setSyncWord(uint8_t sw); | ||||
|   uint8_t modemStatus(); | ||||
|   bool dcd(); | ||||
|   void enableCrc(); | ||||
|   void disableCrc(); | ||||
|   void enableTCXO(); | ||||
|  |  | |||
							
								
								
									
										34
									
								
								sx128x.cpp
									
										
									
									
									
								
							
							
						
						
									
										34
									
								
								sx128x.cpp
									
										
									
									
									
								
							|  | @ -410,23 +410,31 @@ int sx128x::endPacket() { | |||
|   else           { return 1; } | ||||
| } | ||||
| 
 | ||||
| uint8_t sx128x::modemStatus() { | ||||
|     // Imitate the register status from the sx1276 / 78
 | ||||
|     uint8_t buf[2] = {0}; | ||||
|     executeOpcodeRead(OP_GET_IRQ_STATUS_8X, buf, 2); | ||||
|     uint8_t clearbuf[2] = {0}; | ||||
|     uint8_t byte = 0x00; | ||||
| unsigned long preamble_detected_at = 0; | ||||
| unsigned long header_detected_at = 0; | ||||
| extern long lora_preamble_time_ms; | ||||
| extern long lora_header_time_ms; | ||||
| bool sx128x::dcd() { | ||||
|   bool carrier_detected = false; | ||||
|   uint8_t buf[2] = {0}; executeOpcodeRead(OP_GET_IRQ_STATUS_8X, buf, 2); | ||||
| 
 | ||||
|     if ((buf[0] & IRQ_PREAMBLE_DET_MASK_8X) != 0) { | ||||
|         byte = byte | 0x01 | 0x04; | ||||
|         // Clear register after reading
 | ||||
|         clearbuf[0] = IRQ_PREAMBLE_DET_MASK_8X; | ||||
|   if ((buf[1] & IRQ_PREAMBLE_DET_MASK_8X) != 0) { | ||||
|     carrier_detected = true; | ||||
|     if (preamble_detected_at == 0) preamble_detected_at = millis(); | ||||
|     if (millis() - preamble_detected_at > lora_preamble_time_ms + lora_header_time_ms) { | ||||
|       preamble_detected_at = 0; | ||||
|       uint8_t clearbuf[2] = {0}; | ||||
|       clearbuf[1] = IRQ_PREAMBLE_DET_MASK_8X; | ||||
|       executeOpcode(OP_CLEAR_IRQ_STATUS_8X, clearbuf, 2); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|     if ((buf[1] & IRQ_HEADER_DET_MASK_8X) != 0) { byte = byte | 0x02 | 0x04; } | ||||
|     executeOpcode(OP_CLEAR_IRQ_STATUS_8X, clearbuf, 2); | ||||
|   if ((buf[1] & IRQ_HEADER_DET_MASK_8X) != 0) { | ||||
|     carrier_detected = true; | ||||
|     header_detected_at = millis(); | ||||
|   } | ||||
| 
 | ||||
|     return byte; | ||||
|   return carrier_detected; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										2
									
								
								sx128x.h
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								sx128x.h
									
										
									
									
									
								
							|  | @ -69,7 +69,7 @@ public: | |||
|   uint8_t getCodingRate4(); | ||||
|   void setPreambleLength(long preamble_symbols); | ||||
|   void setSyncWord(int sw); | ||||
|   uint8_t modemStatus(); | ||||
|   bool dcd(); | ||||
|   void clearIRQStatus(); | ||||
|   void enableCrc(); | ||||
|   void disableCrc(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Mark Qvist
						Mark Qvist