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 KX022 by
Revision 3:e2d1659fe67e, committed 2016-09-14
- Comitter:
- MikkoZ
- Date:
- Wed Sep 14 09:16:41 2016 +0000
- Parent:
- 2:5ac8e9e5f63e
- Child:
- 4:4038b02c530d
- Commit message:
- Modified init routine to work with other WAI values too. Init tries to setup sensor anyway in hope to find regmap compatible sensor.; Turned on _DEBUG by default.
Changed in this revision
| KX022.cpp | Show annotated file Show diff for this revision Revisions of this file |
| KX022.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/KX022.cpp Wed Mar 23 03:32:14 2016 +0000
+++ b/KX022.cpp Wed Sep 14 09:16:41 2016 +0000
@@ -49,10 +49,11 @@
unsigned char buf;
unsigned char reg[2];
+ DEBUG_PRINT("KX022 init started\n\r");
readRegs(KX022_WHO_AM_I, &buf, sizeof(buf));
if (buf != KX022_WAI_VAL) {
- DEBUG_PRINT("KX022 initialization error. (%d)\n", buf);
- return;
+ DEBUG_PRINT("KX022 initialization error. (WAI %d, not %d)\n\r", buf, KX022_WAI_VAL);
+ DEBUG_PRINT("Trying to config anyway, in case there is some compatible sensor connected.\n\r");
}
reg[0] = KX022_CNTL1;
@@ -110,9 +111,14 @@
void KX022::readRegs(int addr, uint8_t * data, int len)
{
+ int read_nok;
char t[1] = {addr};
+
m_i2c.write(m_addr, t, 1, true);
- m_i2c.read(m_addr, (char *)data, len);
+ read_nok = m_i2c.read(m_addr, (char *)data, len);
+ if (read_nok){
+ DEBUG_PRINT("Read fail\n\r");
+ }
}
void KX022::writeRegs(uint8_t * data, int len)
--- a/KX022.h Wed Mar 23 03:32:14 2016 +0000 +++ b/KX022.h Wed Sep 14 09:16:41 2016 +0000 @@ -47,6 +47,7 @@ #define KX022_ODCNTL (0x1B) #define KX022_TILT_TIMER (0x22) +#define _DEBUG #ifdef _DEBUG extern Serial pc; #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__)
