Cannot communicate between Arduino Uno with LoRa by SPI protocol

I have an assignment, that is rewrite a library of LoRa with protocol is SPI .

I reference the “RH_RF95.h” on github and code in this page.

Then I copy code in page, but it doesn’t work.

Can anyone help me?? Please!!!

I use Arduino Uno R3 and LoRa Shiled v1.4

Thanks for all!!

sx1278_code_20140702_master.ino (24.1 KB)

sx1278_code_20140702_Slaver.ino (23.8 KB)

Please explain exactly what you mean by “it doesn’t work”.

In this code

unsigned char sx1276_7_8_LoRaEntryRx(void)
  unsigned char addr; 
  sx1276_7_8_Config();                                         //setting base parameter
  SPIWrite(REG_LR_PADAC,0x84);                              //Normal and Rx
  SPIWrite(LR_RegHopPeriod,0xFF);                          //RegHopPeriod NO FHSS
  SPIWrite(REG_LR_DIOMAPPING1,0x01);                       //DIO0=00, DIO1=00, DIO2=00, DIO3=01
  SPIWrite(LR_RegIrqFlagsMask,0x3F);                       //Open RxDone interrupt & Timeout
  SPIWrite(LR_RegPayloadLength,21);                       //RegPayloadLength  21byte(this register must difine when the data long of one byte in SF is 6)
  addr = SPIRead(LR_RegFifoRxBaseAddr);           				//Read RxBaseAddr
  SPIWrite(LR_RegFifoAddrPtr,addr);                        //RxBaseAddr -> FiFoAddrPtr
  SPIWrite(LR_RegOpMode,0x8d);                        		//Continuous Rx Mode//Low Frequency Mode
  //SPIWrite(LR_RegOpMode,0x05);                        		//Continuous Rx Mode//High Frequency Mode
  //SysTime = 0;
    if((SPIRead(LR_RegModemStat)&0x04)==0x04)   //Rx-on going RegModemStat
      return 0;                                              //over time for error*/

the program always in loop "while(1)"

If you have a Dragino shield, have you followed the very good instructions they provide to check if your module is working ?

You do need to be specific as to what bits you are using, I took a guess that ‘LoRa Shiled v1.4’ might be a Dragino, but you should provide links so its clear what hardware is involved.

You should be careful following code you find on the Internet, in the link you provided the LoRa device is incorrectly connected. There are no level shifters meaning the LoRa device has probably been destroyed, so pay no credance to the rest of the post.

I have followed their instructions. The LoRa Shield can send and receive string "hello", "hello back",... Everything are working.

I read their library, it was too big. So I found the another source, this page ";area=showposts;u=496207". I compared its, and I saw it almost same.

When I download that source and build it, it didn't work.

What I want is making a simple library for Arduino Uno communicate with LoRa Shiel by using SPI protocol

What I want is making a simple library for Arduino Uno communicate with LoRa Shiel by using SPI protocol

What makes you think that is going to be possible ?

Using the LoRa devices requires quite a bit of register level manipulation, so the libraries are as big as they are in order to drive the LoRa device properly.

Do remember that although a library might appear 'big' the compiler will only use the bits that are needed according to the program you have written. If there are features in the library that you dont use in your code, then the features are not included in your complied code.

I think I can do it

the program always in loop "while(1)"

So what do you think the program is doing when its looping here ?

The comment (in the bit of code) tells you what that bit of code is doing, and you can confim that with a quick check in the SX1278 data sheet.