I am sending temperature array data to teensy SD card along with gps data. It typically runs for 2-3 hours then hangs up, always after it prints out the array data and moves to the gps data. The radio is a RFM69 915 MHz and the gps is the Adafruit Ultimate GPS.
1. Does anyone see a problem with the code that would cause it to infrequently hang?
2. In a post some time ago Paul recommended against using a capacitor to reset but I can't add a chip to this board. Since it is not reliable now is there any reason not to try putting a diode and capacitor on pin 18 so that if it hangs (18 will be low) it drags down the reset?
When it hangs it always prints out the 1234 so has presumably finished the SD card activity and moves on. I have tried moving the disable/enable interrupts around and have even run with them disabled in setup() with no apparent difference.
1. Does anyone see a problem with the code that would cause it to infrequently hang?
2. In a post some time ago Paul recommended against using a capacitor to reset but I can't add a chip to this board. Since it is not reliable now is there any reason not to try putting a diode and capacitor on pin 18 so that if it hangs (18 will be low) it drags down the reset?
When it hangs it always prints out the 1234 so has presumably finished the SD card activity and moves on. I have tried moving the disable/enable interrupts around and have even run with them disabled in setup() with no apparent difference.
Code:
#include <RH_RF69.h>
#include <SPI.h>
//#include <IFCT.h>
//#include <kinetis_flexcan.h>
#include <SD.h>
#include <Adafruit_GPS.h>
//Match frequency to the hardware version of the radio on your Feather
#define RF69_FREQ 915.0
//#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
//#define IS_RFM69HCW true // set to 'true' if you are using an RFM69HCW module
#define SERIAL_BAUD 9600
//for Teensy 3.6 RFM69 Radio for base with CAN bus and BT.
#define RFM69_CS 10
#define RFM69_INT 2
#define RFM69_RST 9
//#define LED 13 // On the 3.6 pin 13 is the rf clock, SCK
File myFile;
File root;
File dir;
File entry;
RH_RF69 rf69(RFM69_CS, RFM69_INT);
int i;byte IDnum=53;int k5;byte cantemp[16];byte b=240;byte b1=1;
const int chipSelect = BUILTIN_SDCARD;
char charNam[11]="AAAAAA.txt";unsigned long reft;unsigned long countms=10;
char charNamlast[11]="AAAAAA.txt";char ctr[2]="A";
char c;//read the NMEA sentence
String NMEA1;
Adafruit_GPS GPS(&Serial3);
#define GPSECHO true
#define LOG_FIXONLY false
boolean usingInterrupt = false;
void useInterrupt(boolean);
int tim;byte k1;byte k2;byte gpsprint=0;int batV;
//SPISettings() { init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0);
SPISettings settingsrf(4000000, MSBFIRST, SPI_MODE0);
SPISettings settingssd(4000000, MSBFIRST, SPI_MODE0);
//****************************************
void setup() {
pinMode(13, OUTPUT); pinMode(18, OUTPUT);
digitalWrite(18,HIGH);
Serial.begin(SERIAL_BAUD);
Serial3.begin(9600);
delay(1000);
Serial.println("RFM69HCW Transmitter");
// Hard Reset the RFM module
pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, HIGH);
delay(100);
digitalWrite(RFM69_RST, LOW);
delay(1000);
if (!rf69.init()) {
Serial.println("RFM69 radio init failed");
while (1);
}
Serial.println("RFM69 radio init OK!");
if (!rf69.setFrequency(RF69_FREQ)) {
Serial.println("setFrequency failed");
}
// If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
// ishighpowermodule flag set like this:
rf69.setTxPower(20, true); // range from 14-20 for power, 2nd arg must be true for 69HCW
// The encryption key has to be the same as the one in the server
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
rf69.setEncryptionKey(key);
Serial.print("RFM69 radio @"); Serial.print((int)RF69_FREQ); Serial.println(" MHz");
if (!SD.begin(chipSelect)) {
Serial.println("card initialization failed!");
return;
}
Serial.println("Program is 'RX_RH_rfm69_3.6_gps_SD_071519'");
Serial.println("card initialized");
delay(1000);
myFile=SD.open(charNam,FILE_WRITE);
Serial.print("file name = ");Serial.println(charNam);
GPS.begin(9600);//Base baud rate so we can talk to gps
// Serial.println("start gps");
delay(1000);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);delay(100);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ); delay(100);
GPS.sendCommand(PGCMD_NOANTENNA);delay(100);
GPS.sendCommand(PMTK_SET_BAUD_57600);delay(100);//Can go to adafruit_gps.h to see these settings
delay(1000);
Serial3.end();delay(100);//Terminate Serial1 then open at the set baud rate
Serial3.begin(57600);delay(100);
GPS.begin(57600);delay(100);
Serial.println("gps restarted");
}
//******************************************************
void loop() {
delay(1);
while(!GPS.newNMEAreceived()) { //Keep reading characters in this loop until a good NMEA sentence is received
c=GPS.read(); //read a character from the GPS
}
NMEA1=GPS.lastNMEA();
Serial.println(NMEA1);myFile.println(NMEA1);
readradiodata();
readradiodata();
if(millis()>countms+600000){
countms=millis();
myFile.close();delay(100);
charNam[5]++;
if (charNam[5]>89){
charNam[5]=65;
}
myFile=SD.open(charNam,FILE_WRITE);
Serial.println(charNam);
}//Closes save/rename loop
}//Closes loop()
//______________________________________________
void readradiodata(){
//delay(50);
digitalWrite(18,HIGH);
if (rf69.available()) {
//Serial.print(millis());
// Should be a message for us now
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf69.recv(buf, &len)) {
__disable_irq();
SPI.beginTransaction(settingsrf);
digitalWrite (10, LOW);
Serial.print(millis());myFile.print(millis());
Serial.print(",");myFile.print(",");
for (k5=0;k5<len;k5++){
Serial.print(buf[k5]);myFile.print(buf[k5],DEC);
if(k5<len){
Serial.print(",");myFile.print(",");
}
}
Serial.println("");myFile.println("");
__enable_irq();
delay(60);
Serial.print("1");
digitalWrite(18,LOW);
Serial.print("2");
digitalWrite (10, HIGH);
Serial.print("3");
SPI.endTransaction();
Serial.print("4"); //IT ALWAYS HANGS HERE!
}//Closes if received
} //Closes if available
}//Closes readradiodata