fix SD card initialization failure
This commit is contained in:
parent
c3ca75f0b2
commit
f3e8354fba
36 changed files with 3109 additions and 2742 deletions
|
|
@ -1,152 +1,152 @@
|
|||
/*
|
||||
RadioLib SX1276 Transmit Example
|
||||
|
||||
This example transmits packets using SX1276 LoRa radio module.
|
||||
Each packet contains up to 256 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
Other modules from SX127x/RFM9x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
|
||||
#include <RadioLib.h>
|
||||
#include "boards.h"
|
||||
|
||||
SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
|
||||
|
||||
|
||||
// flag to indicate that a packet was received
|
||||
volatile bool receivedFlag = false;
|
||||
|
||||
// disable interrupt when it's not needed
|
||||
volatile bool enableInterrupt = true;
|
||||
|
||||
// this function is called when a complete packet
|
||||
// is received by the module
|
||||
// IMPORTANT: this function MUST be 'void' type
|
||||
// and MUST NOT have any arguments!
|
||||
void setFlag(void)
|
||||
{
|
||||
// check if the interrupt is enabled
|
||||
if (!enableInterrupt) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we got a packet, set the flag
|
||||
receivedFlag = true;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
initBoard();
|
||||
// When the power is turned on, a delay is required.
|
||||
delay(1500);
|
||||
|
||||
// initialize SX1262 with default settings
|
||||
Serial.print(F("[SX1262] Initializing ... "));
|
||||
#ifdef LoRa_frequency
|
||||
int state = radio.begin(LoRa_frequency);
|
||||
#else
|
||||
int state = radio.begin(868.0);
|
||||
#endif
|
||||
if (state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
}
|
||||
|
||||
// set the function that will be called
|
||||
// when new packet is received
|
||||
radio.setDio1Action(setFlag);
|
||||
|
||||
// start listening for LoRa packets
|
||||
Serial.print(F("[SX1262] Starting to listen ... "));
|
||||
state = radio.startReceive();
|
||||
if (state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
}
|
||||
|
||||
// if needed, 'listen' mode can be disabled by calling
|
||||
// any of the following methods:
|
||||
//
|
||||
// radio.standby()
|
||||
// radio.sleep()
|
||||
// radio.transmit();
|
||||
// radio.receive();
|
||||
// radio.readData();
|
||||
// radio.scanChannel();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// check if the flag is set
|
||||
if (receivedFlag) {
|
||||
// disable the interrupt service routine while
|
||||
// processing the data
|
||||
enableInterrupt = false;
|
||||
|
||||
// reset flag
|
||||
receivedFlag = false;
|
||||
|
||||
// you can read received data as an Arduino String
|
||||
String str;
|
||||
int state = radio.readData(str);
|
||||
|
||||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
*/
|
||||
|
||||
if (state == ERR_NONE) {
|
||||
// packet was successfully received
|
||||
Serial.println(F("[SX1262] Received packet!"));
|
||||
|
||||
// print data of the packet
|
||||
Serial.print(F("[SX1262] Data:\t\t"));
|
||||
Serial.println(str);
|
||||
|
||||
// print RSSI (Received Signal Strength Indicator)
|
||||
Serial.print(F("[SX1262] RSSI:\t\t"));
|
||||
Serial.print(radio.getRSSI());
|
||||
Serial.println(F(" dBm"));
|
||||
|
||||
// print SNR (Signal-to-Noise Ratio)
|
||||
Serial.print(F("[SX1262] SNR:\t\t"));
|
||||
Serial.print(radio.getSNR());
|
||||
Serial.println(F(" dB"));
|
||||
|
||||
} else if (state == ERR_CRC_MISMATCH) {
|
||||
// packet was received, but is malformed
|
||||
Serial.println(F("CRC error!"));
|
||||
|
||||
} else {
|
||||
// some other error occurred
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
|
||||
}
|
||||
|
||||
// put module back to listen mode
|
||||
radio.startReceive();
|
||||
|
||||
// we're ready to receive more packets,
|
||||
// enable interrupt service routine
|
||||
enableInterrupt = true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
RadioLib SX1276 Transmit Example
|
||||
|
||||
This example transmits packets using SX1276 LoRa radio module.
|
||||
Each packet contains up to 256 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
Other modules from SX127x/RFM9x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
|
||||
#include <RadioLib.h>
|
||||
#include "boards.h"
|
||||
|
||||
SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
|
||||
|
||||
|
||||
// flag to indicate that a packet was received
|
||||
volatile bool receivedFlag = false;
|
||||
|
||||
// disable interrupt when it's not needed
|
||||
volatile bool enableInterrupt = true;
|
||||
|
||||
// this function is called when a complete packet
|
||||
// is received by the module
|
||||
// IMPORTANT: this function MUST be 'void' type
|
||||
// and MUST NOT have any arguments!
|
||||
void setFlag(void)
|
||||
{
|
||||
// check if the interrupt is enabled
|
||||
if (!enableInterrupt) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we got a packet, set the flag
|
||||
receivedFlag = true;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
initBoard();
|
||||
// When the power is turned on, a delay is required.
|
||||
delay(1500);
|
||||
|
||||
// initialize SX1262 with default settings
|
||||
Serial.print(F("[SX1262] Initializing ... "));
|
||||
#ifdef LoRa_frequency
|
||||
int state = radio.begin(LoRa_frequency);
|
||||
#else
|
||||
int state = radio.begin(868.0);
|
||||
#endif
|
||||
if (state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
}
|
||||
|
||||
// set the function that will be called
|
||||
// when new packet is received
|
||||
radio.setDio1Action(setFlag);
|
||||
|
||||
// start listening for LoRa packets
|
||||
Serial.print(F("[SX1262] Starting to listen ... "));
|
||||
state = radio.startReceive();
|
||||
if (state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
}
|
||||
|
||||
// if needed, 'listen' mode can be disabled by calling
|
||||
// any of the following methods:
|
||||
//
|
||||
// radio.standby()
|
||||
// radio.sleep()
|
||||
// radio.transmit();
|
||||
// radio.receive();
|
||||
// radio.readData();
|
||||
// radio.scanChannel();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// check if the flag is set
|
||||
if (receivedFlag) {
|
||||
// disable the interrupt service routine while
|
||||
// processing the data
|
||||
enableInterrupt = false;
|
||||
|
||||
// reset flag
|
||||
receivedFlag = false;
|
||||
|
||||
// you can read received data as an Arduino String
|
||||
String str;
|
||||
int state = radio.readData(str);
|
||||
|
||||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
*/
|
||||
|
||||
if (state == ERR_NONE) {
|
||||
// packet was successfully received
|
||||
Serial.println(F("[SX1262] Received packet!"));
|
||||
|
||||
// print data of the packet
|
||||
Serial.print(F("[SX1262] Data:\t\t"));
|
||||
Serial.println(str);
|
||||
|
||||
// print RSSI (Received Signal Strength Indicator)
|
||||
Serial.print(F("[SX1262] RSSI:\t\t"));
|
||||
Serial.print(radio.getRSSI());
|
||||
Serial.println(F(" dBm"));
|
||||
|
||||
// print SNR (Signal-to-Noise Ratio)
|
||||
Serial.print(F("[SX1262] SNR:\t\t"));
|
||||
Serial.print(radio.getSNR());
|
||||
Serial.println(F(" dB"));
|
||||
|
||||
} else if (state == ERR_CRC_MISMATCH) {
|
||||
// packet was received, but is malformed
|
||||
Serial.println(F("CRC error!"));
|
||||
|
||||
} else {
|
||||
// some other error occurred
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
|
||||
}
|
||||
|
||||
// put module back to listen mode
|
||||
radio.startReceive();
|
||||
|
||||
// we're ready to receive more packets,
|
||||
// enable interrupt service routine
|
||||
enableInterrupt = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,17 +113,6 @@ void initBoard()
|
|||
|
||||
initPMU();
|
||||
|
||||
#ifdef HAS_SDCARD
|
||||
SDSPI.begin(SDCARD_SCLK, SDCARD_MISO, SDCARD_MOSI, SDCARD_CS);
|
||||
if (!SD.begin(SDCARD_CS, SDSPI)) {
|
||||
Serial.println("setupSDCard FAIL");
|
||||
} else {
|
||||
uint32_t cardSize = SD.cardSize() / (1024 * 1024);
|
||||
Serial.print("setupSDCard PASS . SIZE = ");
|
||||
Serial.print(cardSize);
|
||||
Serial.println(" MB");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_LED
|
||||
/*
|
||||
|
|
@ -162,10 +151,61 @@ void initBoard()
|
|||
} while ( u8g2->nextPage() );
|
||||
u8g2->sendBuffer();
|
||||
u8g2->setFont(u8g2_font_fur11_tf);
|
||||
delay(5000);
|
||||
delay(3000);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAS_SDCARD
|
||||
if (u8g2) {
|
||||
u8g2->setFont(u8g2_font_ncenB08_tr);
|
||||
}
|
||||
pinMode(SDCARD_MISO, INPUT_PULLUP);
|
||||
SDSPI.begin(SDCARD_SCLK, SDCARD_MISO, SDCARD_MOSI, SDCARD_CS);
|
||||
if (u8g2) {
|
||||
u8g2->clearBuffer();
|
||||
}
|
||||
|
||||
if (!SD.begin(SDCARD_CS, SDSPI)) {
|
||||
|
||||
Serial.println("setupSDCard FAIL");
|
||||
if (u8g2) {
|
||||
do {
|
||||
u8g2->setCursor(0, 16);
|
||||
u8g2->println( "SDCard FAILED");;
|
||||
} while ( u8g2->nextPage() );
|
||||
}
|
||||
|
||||
} else {
|
||||
uint32_t cardSize = SD.cardSize() / (1024 * 1024);
|
||||
if (u8g2) {
|
||||
do {
|
||||
u8g2->setCursor(0, 16);
|
||||
u8g2->print( "SDCard:");;
|
||||
u8g2->print(cardSize / 1024.0);;
|
||||
u8g2->println(" GB");;
|
||||
} while ( u8g2->nextPage() );
|
||||
}
|
||||
|
||||
Serial.print("setupSDCard PASS . SIZE = ");
|
||||
Serial.print(cardSize / 1024.0);
|
||||
Serial.println(" GB");
|
||||
}
|
||||
if (u8g2) {
|
||||
u8g2->sendBuffer();
|
||||
}
|
||||
delay(3000);
|
||||
#endif
|
||||
|
||||
if (u8g2) {
|
||||
u8g2->clearBuffer();
|
||||
do {
|
||||
u8g2->setCursor(0, 16);
|
||||
u8g2->println( "Waiting to receive data");;
|
||||
} while ( u8g2->nextPage() );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue