Code:
/* ARDUINO One-Page LoRa TRANSMITTER
*
* AI Ra-01_V1.0 Semtech SX1278 ****** NOT BREADBOARD FRIENDLY !!!! ******
*
* Powered from computer usb or phone charger via FTDI module with jumper at 3.3V
*
* LoRa Arduino
* 3.3V VCC THREE POINT THREE VOLTS !!!.!!!
* GND GND
* SCK SCK (13)
* MISO MISO (12)
* MOSI MOSI (11)
* NSS 10
* RESET 9
*/
#include <SPI.h>
const int nss = 10;
const int reset = 9;
const int lora_int = 2;
byte data = 0;
byte tx_base = 0x80;
byte regIrqFlags = 0;
void setup() {
pinMode(reset,OUTPUT);
pinMode(nss, OUTPUT);
digitalWrite(nss,HIGH);
digitalWrite(reset,HIGH);
SPI.begin();
Serial.begin(9600);
// CONFIG TX
digitalWrite(reset,LOW);
delayMicroseconds(100); // reset low 100 usec
digitalWrite(reset,HIGH);
delay(10); // time to reset, mini 5 msec
digitalWrite(nss,LOW);
SPI.transfer(0x81); SPI.transfer(0x00); // Need to be in sleep mode to set LoRa mode
digitalWrite(nss,HIGH);
digitalWrite(nss,LOW);
SPI.transfer(0x81); SPI.transfer(0x88); // LoRa, low freq mode
digitalWrite(nss,HIGH);
digitalWrite(nss,LOW);
SPI.transfer(0x89); SPI.transfer(0xF3); // PA_BOOST
digitalWrite(nss,HIGH);
digitalWrite(nss,LOW);
SPI.transfer(0x91); SPI.transfer(0xF7); // Set up for TXDone IRQ
digitalWrite(nss,HIGH);
}
void loop() { // TRANSMIT 1 byte payload
digitalWrite(nss,LOW);
SPI.transfer(0x81); SPI.transfer(0x09); // standby mode to set up packet
digitalWrite(nss,HIGH);
digitalWrite(nss,LOW);
SPI.transfer(0x8D); SPI.transfer(tx_base); // set SPI pointer
digitalWrite(nss,HIGH);
digitalWrite(nss,LOW);
SPI.transfer(0x80); SPI.transfer(data); // Write the byte to Fifo
digitalWrite(nss,HIGH);
digitalWrite(nss,LOW);
SPI.transfer(0x81); SPI.transfer(0x8B); // TX on, low freq mode (send the byte)
digitalWrite(nss,HIGH);
delay(100);
digitalWrite(nss,LOW);
SPI.transfer(0x12);regIrqFlags = SPI.transfer(0x00); // Get flags reg
digitalWrite(nss,HIGH);
if(regIrqFlags) { // TXDone
digitalWrite(nss,LOW);
SPI.transfer(0x92); SPI.transfer(0xFF); // Set flags reg to zero
digitalWrite(nss,HIGH);
Serial.print("Sent ");
Serial.println(data);
}
digitalWrite(nss,LOW);
SPI.transfer(0x81); SPI.transfer(0x88); // TX and RX to sleep in LoRa mode (clear Fifo)
digitalWrite(nss,HIGH);
data=(data<10)?data+1:0; // If data<10 then data=data+1 else data=0
delay(900);
}