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 AK9752 by
Diff: AK9752.cpp
- Revision:
- 4:2f4c8e641ce9
- Parent:
- 2:0b59cfeee8ee
--- a/AK9752.cpp Tue Nov 01 17:49:01 2016 +0000
+++ b/AK9752.cpp Wed Nov 02 00:14:52 2016 +0000
@@ -1,5 +1,6 @@
#include "AK9752.h"
#include "AK9752_reg.h"
+#include "debug.h"
#define CONV16I(high,low) ((int16_t)(((high) << 8) | (low)))
@@ -26,32 +27,38 @@
}
AK9752::Status AK9752::checkConnection() {
- AK9752::Status status = AK9752::SUCCESS;
+ //AK9752::Status status = AK9752::SUCCESS;
- // Gets the WIA register value.
+ // Gets the WIA register value - ID and ID2
char buf[2];
- if ((status=AK9752::read(AK9752_REG_ADDR_WIA1, buf, 2)) != SUCCESS) {
- return status;
+ if ((AK9752::read(AK9752_REG_ADDR_WIA1, buf, 2)) != AK9752::SUCCESS) {
+ MSG("Read of WIA1 failed.\r\n");
+ return AK9752::ERROR;
}
// Checks the obtained value equals to the supposed value.
- if ( (buf[0] != AK9752_REG_VALUE_WIA1) || (buf[1] != AK9752_REG_VALUE_WIA2) ) {
- return AK9752::ERROR;
+ if ( (buf1 != AK9752_REG_VALUE_WIA1) || (buf2 != AK9752_REG_VALUE_WIA2) ) {
+ MSG("ID check failed.\r\n");
+ MSG("WIA1: %d\r\n", buf[0]);
+ MSG("WIA2: %d\r\n", buf[1]);
+ // return AK9752::ERROR;
}
- return status;
+ return AK9752::SUCCESS;
}
AK9752::Status AK9752::read(char registerAddress, char *buf, int length) {
// Writes the first register address
if (connection->write((slaveAddress << 1), ®isterAddress, LEN_ONE_BYTE) != 0) {
// I2C write failed.
+ MSG("Error: I2C write failure.\r\n");
return AK9752::ERROR_I2C_WRITE;
}
// Reads register data
if (connection->read((slaveAddress << 1), buf, length) != 0) {
// I2C read failed.
+ MSG("Error: I2C read failure.\r\n");
return AK9752::ERROR_I2C_READ;
}
