Created Debug mode (markdown)

master
Jan Gromeš 2020-06-27 07:48:13 +02:00
rodzic f40e43c577
commit 9b573e5ace
1 zmienionych plików z 35 dodań i 0 usunięć

35
Debug-mode.md 100644

@ -0,0 +1,35 @@
When something isn't working as expected, it might be useful to take a peek "under the hood", to find out what exactly is RadioLib doing, and where it might be failing. For that purpose, there's a couple of debugging options that can be used.
## Enabling debug
To enable debug, you can go to the [BuildOpt.h](https://github.com/jgromes/RadioLib/blob/master/src/BuildOpt.h) file, and uncomment either one or both of these lines:
```c++
//#define RADIOLIB_DEBUG
//#define RADIOLIB_VERBOSE
```
Alternatively, you can define the debug macros in the Arduino sketch - much like [custom build configuration](https://github.com/jgromes/RadioLib/wiki/Custom-Build-Configuration), this must be done prior to including the main library header file:
```c++
#define RADIOLIB_DEBUG
#define RADIOLIB_VERBOSE
#include <RadioLib.h>
void setup() {
// etc.
}
```
The default debug port is set to `Serial`, on most Arduino boards, this should correspond to the Serial port connected to USB. If you want to use a different port, simply change the value of `RADIOLIB_DEBUG_PORT` macro to e.g. `Serial2`, or whichever Serial port you want to use. `SoftwareSerial` ports are supported as well.
__NOTE:__ RadioLib DOES NOT automatically initialize the debug port with `Serial.begin()`. This is done to prevent collisions when user already calls the `begin()` method from Arduino sketch. For that reason, debug interface initialization MUST be done prior to RadioLib module initialization (e.g. `lora.begin()`, otherwise there will be no debug output from the `begin()` method.
## Debug levels
### RADIOLIB_DEBUG
Enabling this macro will only print out basic debug info - for example, when writing to an SPI register fails. This is useful on modules like SX127x or RF69, which use direct SPI register access.
### RADIOLIB_VERBOSE
Enabling this macro will print out full transcript of all SPI or UART communication. This is useful on modules like SX126x or UART-based modules, which have command-based interface (instead of SPI register transfers).