Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of AS3935 by
Diff: AS3935.cpp
- Revision:
- 3:c536a9aa2a1c
- Parent:
- 2:3b3b435ca8d9
- Child:
- 4:ab1f1b65468b
--- a/AS3935.cpp Thu Jun 11 15:53:51 2015 +0000
+++ b/AS3935.cpp Thu Jun 11 19:45:11 2015 +0000
@@ -21,7 +21,7 @@
#include "AS3935.h"
#include "pinmap.h"
-AS3935::AS3935(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name, PinName cd, int hz) : m_Spi(mosi, miso, sclk), m_Cs(cs, 1), m_Cd(cd), m_FREQ(hz)
+AS3935::AS3935(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name, int hz) : m_Spi(mosi, miso, sclk), m_Cs(cs, 1), m_FREQ(hz)
{
//Enable the internal pull-up resistor on MISO
@@ -29,6 +29,9 @@
//Configure the SPI bus
m_Spi.format(8, 1);
+ printf("spi bus frequency set to %d hz\r\n",hz);
+ m_Spi.frequency(hz);
+
}
char AS3935::_SPITransfer2(char high, char low)
@@ -201,4 +204,33 @@
registerWrite(AS3935_CL_STAT,1);
registerWrite(AS3935_CL_STAT,0);
registerWrite(AS3935_CL_STAT,1);
-}
\ No newline at end of file
+}
+
+int AS3935::calibrateRCOs (void)
+{
+ int rc;
+ uint8_t trco;
+ uint8_t srco;
+ m_Cs = 0;
+ m_Spi.write(0x3D); // Direct Command Calibrate RCO
+ m_Spi.write(0x96);
+ m_Cs = 1;
+ wait_ms(1); // wait 1ms
+ registerWrite(0x08, 0x40, 0x40); // ERRATA: after power down mode
+ wait_ms(2); // wait 1ms
+ registerWrite(0x08, 0x40, 0x00); // ERRATA: after power down mode
+ trco=registerRead(0x3A, 0x80); // Read out Calibration of TRCO done
+ srco=registerRead(0x3B, 0x80); // Readout Calibration of SRCO done
+ if(trco != 0x00 && srco != 0x00)
+ {
+ rc = 1;
+ printf("cal is done\r\n");
+ }
+ else
+ {
+ printf("cal is not done\r\n");
+ rc = 0;
+ }
+
+ return rc;
+}
