■ ■ ■ ■ ■ ■
firmwareSAMD/catSinffer_test/catSinffer_test.ino
| 1 | + | #include <RadioLib.h> |
| 2 | + | |
| 3 | + | #define CTF1 14 |
| 4 | + | #define CTF2 11 |
| 5 | + | #define CTF3 10 |
| 6 | + | |
| 7 | + | |
| 8 | + | // SX1262 has the following connections: |
| 9 | + | // NSS pin: 17 |
| 10 | + | // DIO1 pin: 3 |
| 11 | + | // NRST pin: 8 |
| 12 | + | // BUSY pin: 2 |
| 13 | + | SX1262 radio = new Module(17, 3, 8, 2); |
| 14 | + | |
| 15 | + | // or using RadioShield |
| 16 | + | // https://github.com/jgromes/RadioShield |
| 17 | + | //SX1262 radio = RadioShield.ModuleA; |
| 18 | + | |
| 19 | + | unsigned long baud = 500000; |
| 20 | + | |
| 21 | + | //unsigned long baud = 57600;//Baud for Zigbee2MQTT |
| 22 | + | //unsigned long baud = 115200;//Baud for Zigbee2MQTT |
| 23 | + | |
| 24 | + | //Pin declaration to enter bootloader mode on CC1352 |
| 25 | + | #define Pin_Reset (1) |
| 26 | + | #define Pin_Boot (7) |
| 27 | + | |
| 28 | + | void setup() { |
| 29 | + | //Begin Serial ports |
| 30 | + | Serial.begin(baud); |
| 31 | + | Serial1.begin(baud); |
| 32 | + | |
| 33 | + | //Assign the attribute of OUTPUT to our pins |
| 34 | + | pinMode(Pin_Reset, OUTPUT); |
| 35 | + | pinMode(Pin_Boot, OUTPUT); |
| 36 | + | |
| 37 | + | //Enter bootloader mode function |
| 38 | + | digitalWrite(Pin_Boot, LOW); |
| 39 | + | delay(100); |
| 40 | + | digitalWrite(Pin_Reset, LOW); |
| 41 | + | delay(100); |
| 42 | + | digitalWrite(Pin_Reset, HIGH); |
| 43 | + | delay(100); |
| 44 | + | digitalWrite(Pin_Boot, HIGH); |
| 45 | + | while(!Serial); |
| 46 | + | |
| 47 | + | pinMode(CTF1, OUTPUT); |
| 48 | + | pinMode(CTF2, OUTPUT); |
| 49 | + | pinMode(CTF3, OUTPUT); |
| 50 | + | |
| 51 | + | digitalWrite(CTF1, HIGH); |
| 52 | + | digitalWrite(CTF2, LOW); |
| 53 | + | digitalWrite(CTF3, LOW); |
| 54 | + | |
| 55 | + | // initialize SX1262 with default settings |
| 56 | + | Serial.print(F("[SX1262] Initializing ... ")); |
| 57 | + | //debing(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) |
| 58 | + | int state = radio.begin(915.0, 250, 7, 5, 0x34, 20, 10, 0, false); |
| 59 | + | if (state == ERR_NONE) { |
| 60 | + | Serial.println(F("success!")); |
| 61 | + | } else { |
| 62 | + | Serial.print(F("failed, code ")); |
| 63 | + | Serial.println(state); |
| 64 | + | while (true); |
| 65 | + | } |
| 66 | + | |
| 67 | + | // some modules have an external RF switch |
| 68 | + | // controlled via two pins (RX enable, TX enable) |
| 69 | + | // to enable automatic control of the switch, |
| 70 | + | // call the following method |
| 71 | + | // RX enable: 4 |
| 72 | + | // TX enable: 5 |
| 73 | + | |
| 74 | + | radio.setRfSwitchPins(16, 15); |
| 75 | + | |
| 76 | + | } |
| 77 | + | |
| 78 | + | void loop() { |
| 79 | + | //SerialPassthrough |
| 80 | + | if (Serial.available()) { // If anything comes in Serial (USB), |
| 81 | + | Serial1.write(Serial.read()); // read it and send it out Serial1 (pins 0 & 1) |
| 82 | + | } |
| 83 | + | |
| 84 | + | if (Serial1.available()) { // If anything comes in Serial1 (pins 0 & 1) |
| 85 | + | Serial.write(Serial1.read()); // read it and send it out Serial (USB) |
| 86 | + | } |
| 87 | + | } |
| 88 | + | |