first commit

This commit is contained in:
2021-05-11 20:43:42 +03:00
commit 9f3ffaba30
381 changed files with 69596 additions and 0 deletions

View File

@@ -0,0 +1,180 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 09/02/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This is a test transmitter for the Fast Long Range Communication (FLRC) mode
introduced in the SX128X devices. A packet containing ASCII text is sent according to the frequency and
FLRC settings specified in the 'Settings.h' file. The pins to access the SX128X device need to be defined
in the 'Settings.h' file also.
The details of the packet sent and any errors are shown on the Serial Monitor, together with the transmit
power used, the packet length and the CRC of the packet. The matching receive program, '53_FLRC_Receiver'
can be used to check the packets are being sent correctly, the frequency and FLRC settings (in Settings.h)
must be the same for the Transmit and Receive program. Sample Serial Monitor output;
10dBm Packet> {packet contents*} BytesSent,23 CRC,DAAB TransmitTime,54mS PacketsSent,1
Serial monitor baud rate is set at 9600
*******************************************************************************************************/
#define Program_Version "V1.0"
#include <SPI.h> //the SX128X device is SPI based so load the SPI library
#include <SX128XLT.h> //include the appropriate library
#include "Settings.h" //include the setiings file, frequencies, LoRa settings etc
SX128XLT LT; //create a library class instance called LT
uint8_t TXPacketL;
uint32_t TXPacketCount, startmS, endmS;
uint8_t buff[] = "Hello World 1234567890";
void loop()
{
Serial.print(TXpower); //print the transmit power defined
Serial.print(F("dBm "));
Serial.print(F("Packet> "));
Serial.flush();
TXPacketL = sizeof(buff); //set TXPacketL to length of array
buff[TXPacketL - 1] = '*'; //replace null character at buffer end so its visible on reciver
LT.printASCIIPacket(buff, TXPacketL); //print the buffer (the sent packet) as ASCII
digitalWrite(LED1, HIGH);
startmS = millis(); //start transmit timer
if (LT.transmit(buff, TXPacketL, 10000, TXpower, WAIT_TX)) //will return packet length sent if OK, otherwise 0 if transmit, timeout 10 seconds
{
endmS = millis(); //packet sent, note end time
TXPacketCount++;
packet_is_OK();
}
else
{
packet_is_Error(); //transmit packet returned 0, there was an error
}
digitalWrite(LED1, LOW);
Serial.println();
delay(packet_delay); //have a delay between packets
}
void packet_is_OK()
{
//if here packet has been sent OK
uint16_t localCRC;
Serial.print(F(" BytesSent,"));
Serial.print(TXPacketL); //print transmitted packet length
localCRC = LT.CRCCCITT(buff, TXPacketL, 0xFFFF);
Serial.print(F(" CRC,"));
Serial.print(localCRC, HEX); //print CRC of sent packet
Serial.print(F(" TransmitTime,"));
Serial.print(endmS - startmS); //print transmit time of packet
Serial.print(F("mS"));
Serial.print(F(" PacketsSent,"));
Serial.print(TXPacketCount); //print total of packets sent OK
}
void packet_is_Error()
{
//if here there was an error transmitting packet
uint16_t IRQStatus;
IRQStatus = LT.readIrqStatus(); //read the the interrupt register
Serial.print(F(" SendError,"));
Serial.print(F("Length,"));
Serial.print(TXPacketL); //print transmitted packet length
Serial.print(F(",IRQreg,"));
Serial.print(IRQStatus, HEX); //print IRQ status
LT.printIrqStatus(); //prints the text of which IRQs set
}
void led_Flash(uint16_t flashes, uint16_t delaymS)
{
uint16_t index;
for (index = 1; index <= flashes; index++)
{
digitalWrite(LED1, HIGH);
delay(delaymS);
digitalWrite(LED1, LOW);
delay(delaymS);
}
}
void setup()
{
pinMode(LED1, OUTPUT); //setup pin as output for indicator LED
led_Flash(2, 125); //two quick LED flashes to indicate program start
Serial.begin(9600);
Serial.println();
Serial.print(F(__TIME__));
Serial.print(F(" "));
Serial.println(F(__DATE__));
Serial.println(F(Program_Version));
Serial.println();
Serial.println(F("52_FLRC_Transmitter Starting"));
SPI.begin();
//SPI beginTranscation is normally part of library routines, but if it is disabled in library
//a single instance is needed here, so uncomment the program line below
//SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
//setup hardware pins used by device, then check if device is found
if (LT.begin(NSS, NRESET, RFBUSY, DIO1, DIO2, DIO3, RX_EN, TX_EN, LORA_DEVICE))
{
Serial.println(F("LoRa Device found"));
led_Flash(2, 125); //two further quick LED flashes to indicate device found
delay(1000);
}
else
{
Serial.println(F("No device responding"));
while (1)
{
led_Flash(50, 50); //long fast speed LED flash indicates device error
}
}
//The function call list below shows the complete setup for the LoRa device using the information defined in the
//Settings.h file.
//***************************************************************************************************
//Setup FLRC
//***************************************************************************************************
LT.setMode(MODE_STDBY_RC);
LT.setRegulatorMode(USE_LDO);
LT.setPacketType(PACKET_TYPE_FLRC);
LT.setRfFrequency(Frequency, Offset);
LT.setBufferBaseAddress(0, 0);
LT.setModulationParams(BandwidthBitRate, CodingRate, BT);
LT.setPacketParams(PREAMBLE_LENGTH_32_BITS, FLRC_SYNC_WORD_LEN_P32S, RADIO_RX_MATCH_SYNCWORD_1, RADIO_PACKET_VARIABLE_LENGTH, 127, RADIO_CRC_3_BYTES, RADIO_WHITENING_OFF);
LT.setDioIrqParams(IRQ_RADIO_ALL, (IRQ_TX_DONE + IRQ_RX_TX_TIMEOUT), 0, 0); //set for IRQ on TX done and timeout on DIO1
LT.setSyncWord1(Sample_Syncword);
//***************************************************************************************************
Serial.println();
LT.printModemSettings(); //reads and prints the configured modem settings, useful check
Serial.println();
LT.printOperatingSettings(); //reads and prints the configured operating settings, useful check
Serial.println();
Serial.println();
LT.printRegisters(0x900, 0x9FF); //print contents of device registers
Serial.println();
Serial.println();
Serial.print(F("Transmitter ready"));
Serial.println();
}

View File

@@ -0,0 +1,40 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 06/02/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of my own boards, the Easy Pro Mini,
//be sure to change the definitions to match your own setup. Some pins such as DIO2,
//DIO3, BUZZER may not be in used by this sketch so they do not need to be
//connected and should be included and be set to -1.
#define NSS 10
#define RFBUSY 7
#define NRESET 9
#define LED1 8
#define DIO1 3
#define DIO2 -1 //not used
#define DIO3 -1 //not used
#define RX_EN -1 //pin for RX enable, used on some SX1280 devices, set to -1 if not used
#define TX_EN -1 //pin for TX enable, used on some SX1280 devices, set to -1 if not used
#define BUZZER -1 //connect a buzzer here if wanted
#define LORA_DEVICE DEVICE_SX1280 //we need to define the device we are using
//FLRC Modem Parameters
const uint32_t Frequency = 2445000000; //frequency of transmissions
const int32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t BandwidthBitRate = FLRC_BR_1_300_BW_1_2; //FLRC bandwidth and bit rate, 1.3Mbs
const uint8_t CodingRate = FLRC_CR_1_2; //FLRC coding rate
const uint8_t BT = RADIO_MOD_SHAPING_BT_1_0; //FLRC BT
const uint32_t Sample_Syncword = 0x01234567; //FLRC uses syncword
const int8_t TXpower = 0; //power for transmissions in dBm
const uint16_t packet_delay = 1000; //mS delay between packets