Commit ee67b5ae871b13882222fc829ff0f6db3c57ac0b

Authored by Thomas Telkamp
1 parent 73408d11

Support for SX1276/RFM95W

Showing 2 changed files with 57 additions and 26 deletions   Show diff stats
README.md
... ... @@ -4,7 +4,7 @@ This repository contains a proof-of-concept implementation of a single
4 4 channel LoRaWAN gateway.
5 5  
6 6 It has been tested on the Raspberry Pi platform, using a Semtech SX1272
7   -transceiver (HopeRF RFM92W).
  7 +transceiver (HopeRF RFM92W), and SX1276 (HopeRF RFM95W).
8 8  
9 9 The code is for testing and development purposes only, and is not meant
10 10 for production usage.
... ... @@ -23,7 +23,6 @@ Features
23 23  
24 24 Not (yet) supported:
25 25 - PACKET_PUSH_ACK processing
26   -- SX1276
27 26 - SF7BW250 modulation
28 27 - FSK modulation
29 28 - downstream messages (tx)
... ... @@ -48,7 +47,7 @@ MOSI - MOSI (pin #19)
48 47 SCK - CLK (pin #23)
49 48 NSS - GPIO6 (pin #22)
50 49 DIO0 - GPIO7 (pin #7)
51   -RST - GPIO0 (in #11)
  50 +RST - GPIO0 (pin #11)
52 51  
53 52 Configuration
54 53 -------------
... ...
main.cpp
... ... @@ -40,6 +40,8 @@ byte currentMode = 0x81;
40 40 char message[256];
41 41 char b64[256];
42 42  
  43 +bool sx1272 = true;
  44 +
43 45 byte receivedbytes;
44 46  
45 47 struct sockaddr_in si_other;
... ... @@ -77,9 +79,9 @@ float lon=0.0;
77 79 int alt=0;
78 80  
79 81 /* Informal status fields */
80   -static char platform[24] = "SX1272"; /* platform definition */
81   -static char email[40] = ""; /* used for contact email */
82   -static char description[64] = ""; /* used for free form description */
  82 +static char platform[24] = "Single Channel Gateway"; /* platform definition */
  83 +static char email[40] = ""; /* used for contact email */
  84 +static char description[64] = ""; /* used for free form description */
83 85  
84 86 // define servers
85 87 // TODO: use host names and dns
... ... @@ -102,6 +104,7 @@ static char description[64] = ""; /* used for free form description */
102 104 #define REG_DIO_MAPPING_2 0x41
103 105 #define REG_MODEM_CONFIG 0x1D
104 106 #define REG_MODEM_CONFIG2 0x1E
  107 +#define REG_MODEM_CONFIG3 0x26
105 108 #define REG_SYMB_TIMEOUT_LSB 0x1F
106 109 #define REG_PKT_SNR_VALUE 0x19
107 110 #define REG_PAYLOAD_LENGTH 0x22
... ... @@ -237,18 +240,34 @@ boolean receivePkt(char *payload)
237 240  
238 241 void SetupLoRa()
239 242 {
  243 +
  244 + digitalWrite(RST, HIGH);
  245 + delay(100);
  246 + digitalWrite(RST, LOW);
  247 + delay(100);
240 248  
241 249 byte version = readRegister(REG_VERSION);
242   - if (version == 0x12) {
243   - // sx1276
244   - printf("SX1276 transceiver not yet supported.\n");
245   - exit(1);
246   - } else if (version == 0x22) {
  250 +
  251 + if (version == 0x22) {
247 252 // sx1272
248 253 printf("SX1272 detected, starting.\n");
  254 + sx1272 = true;
249 255 } else {
250   - printf("Unrecognized transceiver.\n");
251   - exit(1);
  256 + // sx1276?
  257 + digitalWrite(RST, LOW);
  258 + delay(100);
  259 + digitalWrite(RST, HIGH);
  260 + delay(100);
  261 + version = readRegister(REG_VERSION);
  262 + if (version == 0x12) {
  263 + // sx1276
  264 + printf("SX1276 detected, starting.\n");
  265 + sx1272 = false;
  266 + } else {
  267 + printf("Unrecognized transceiver.\n");
  268 + //printf("Version: 0x%x\n",version);
  269 + exit(1);
  270 + }
252 271 }
253 272  
254 273 writeRegister(REG_OPMODE, SX72_MODE_SLEEP);
... ... @@ -261,12 +280,22 @@ void SetupLoRa()
261 280  
262 281 writeRegister(REG_SYNC_WORD, 0x34); // LoRaWAN public sync word
263 282  
264   - if (sf == SF11 || sf == SF12) {
265   - writeRegister(REG_MODEM_CONFIG,0x0B);
  283 + if (sx1272) {
  284 + if (sf == SF11 || sf == SF12) {
  285 + writeRegister(REG_MODEM_CONFIG,0x0B);
  286 + } else {
  287 + writeRegister(REG_MODEM_CONFIG,0x0A);
  288 + }
  289 + writeRegister(REG_MODEM_CONFIG2,(sf<<4) | 0x04);
266 290 } else {
267   - writeRegister(REG_MODEM_CONFIG,0x0A);
  291 + if (sf == SF11 || sf == SF12) {
  292 + writeRegister(REG_MODEM_CONFIG3,0x0C);
  293 + } else {
  294 + writeRegister(REG_MODEM_CONFIG3,0x04);
  295 + }
  296 + writeRegister(REG_MODEM_CONFIG,0x072);
  297 + writeRegister(REG_MODEM_CONFIG2,(sf<<4) | 0x04);
268 298 }
269   - writeRegister(REG_MODEM_CONFIG2,(sf<<4) | 0x04);
270 299  
271 300 if (sf == SF10 || sf == SF11 || sf == SF12) {
272 301 writeRegister(REG_SYMB_TIMEOUT_LSB,0x05);
... ... @@ -350,6 +379,7 @@ void sendstat() {
350 379 void receivepacket() {
351 380  
352 381 long int SNR;
  382 + int rssicorr;
353 383  
354 384 if(digitalRead(dio0) == 1)
355 385 {
... ... @@ -366,8 +396,15 @@ void receivepacket() {
366 396 // Divide by 4
367 397 SNR = ( value & 0xFF ) >> 2;
368 398 }
369   - printf("Packet RSSI: %d, ",readRegister(0x1A)-139);
370   - printf("RSSI: %d, ",readRegister(0x1B)-139);
  399 +
  400 + if (sx1272) {
  401 + rssicorr = 139;
  402 + } else {
  403 + rssicorr = 157;
  404 + }
  405 +
  406 + printf("Packet RSSI: %d, ",readRegister(0x1A)-rssicorr);
  407 + printf("RSSI: %d, ",readRegister(0x1B)-rssicorr);
371 408 printf("SNR: %li, ",SNR);
372 409 printf("Length: %i",(int)receivedbytes);
373 410 printf("\n");
... ... @@ -463,7 +500,7 @@ void receivepacket() {
463 500 buff_index += 13;
464 501 j = snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buff_index, ",\"lsnr\":%li", SNR);
465 502 buff_index += j;
466   - j = snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buff_index, ",\"rssi\":%d,\"size\":%u", readRegister(0x1A)-139, receivedbytes);
  503 + j = snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buff_index, ",\"rssi\":%d,\"size\":%u", readRegister(0x1A)-rssicorr, receivedbytes);
467 504 buff_index += j;
468 505 memcpy((void *)(buff_up + buff_index), (void *)",\"data\":\"", 9);
469 506 buff_index += 9;
... ... @@ -504,12 +541,7 @@ int main () {
504 541 pinMode(dio0, INPUT);
505 542 pinMode(RST, OUTPUT);
506 543  
507   - digitalWrite(RST, HIGH);
508   - delay(100);
509   - digitalWrite(RST, LOW);
510   - delay(200);
511   -
512   - //int fd = ;
  544 + //int fd =
513 545 wiringPiSPISetup(CHANNEL, 500000);
514 546 //cout << "Init result: " << fd << endl;
515 547  
... ...