I have a series of devices that measure acceleration, record to an SD, and communicate via a LoRa data radio.
The base component Feather 32u4 Adalogger with the AtMega32u4 core and on-board microSD: http://learn.adafruit.com/adafruit-feather-32u4-adalogger/overview
RFM95W Featherwing equipped with Semtech 127x Radio: http://learn.adafruit.com/radio-featherwing/overview
Radio datasheet, manufactured by HOPERF: http://cdn-learn.adafruit.com/assets/assets/000/031/659/original/RFM95_96_97_98W.pdf?1460518717
The devices above compose the “measurement” device, each is equipped with an accelerometer that is connected to the analog pins GND & A0-A4.
I have one more device that is the “controlling” device, which also uses the AtMega32u4, it handles the user input and sends commands to the “measurement” devices. http://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/
I am using two major libraries, RadioHead and SdFat. The latter I have trimmed down significantly because I simply want to record data in binary and do all of the CSV conversions post measurement. I am also using the SPI library to handle transactions between the two peripheral devices, the SD and the Radio, or let's say I was optimistic at one point that this might solve my problem.
Radio
Class reference for the RH_RF95 radio driver: http://www.airspayce.com/mikem/arduino/RadioHead/classRH__RF95.html
Class reference for the radio manager: RadioHead: RHReliableDatagram Class Reference
SD Library
The SdFat Library: GitHub - greiman/SdFat: Arduino FAT16/FAT32 exFAT Library
The code for the “measurement” devices is where my problem is, I have each library functioning on these devices separately but an issue arises when I try to couple the Radio and SD codes. The controller is successfully communicating with the measurement devices, commands come from the controller as 1, 2, or 3. The switch statement then executes the desired command.
When the command “2” is issued, the program calls the function logFile, which it has no problem executing. At the end of these functions, the code mysteriously hangs, printing to the serial monitor isn't always possible, sometimes it will, but the radio never regains control.
I have to believe that this is some interference with the SPI interface, I have read that the SD will not share the SPI very kindly, i.e. release MISO, which I was hoping that driving the CS high and using transactions would cure but to no avail.
I would like anyone to speak there mind on what they perceive the best course of action would be. I am very new at this, most recently I was considering moving steps where I need to execute radio commands into some kind of ISR but my understanding of how to do that is limited.
I cannot post the code in code tags, unfortunately it puts this post over 9000 characters, I have attached the file Accel_Server.ino.
An image from the Serial monitor of the controlling device and corresponding response from the measurement device is attached ControlMonitor_MeasMonitor.PNG. This may help with understanding the program flow that I am trying to achieve.
Thanks in advance!
-J
Accel_Server.ino (25.3 KB)