Skip to content

Commit 7bc3c4f

Browse files
committed
[SensorQMC6310] Fix QMC6310 multiple device addresses
1 parent e005e43 commit 7bc3c4f

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

examples/QMC6310_CalibrateExample/QMC6310_CalibrateExample.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void setup()
175175

176176
beginPower();
177177

178-
if (!qmc.begin(Wire, SENSOR_SDA, SENSOR_SCL)) {
178+
if (!qmc.begin(Wire, QMC6310U_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL)) {
179179
Serial.println("Failed to find QMC6310 - check your wiring!");
180180
while (1) {
181181
delay(1000);

examples/QMC6310_CompassExample/QMC6310_CompassExample.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void setup()
110110

111111
beginPower();
112112

113-
if (!qmc.begin(Wire, SENSOR_SDA, SENSOR_SCL)) {
113+
if (!qmc.begin(Wire, QMC6310U_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL)) {
114114
Serial.println("Failed to find QMC6310 - check your wiring!");
115115
while (1) {
116116
delay(1000);

examples/QMC6310_GetDataExample/QMC6310_GetDataExample.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void setup()
6868

6969
beginPower();
7070

71-
if (!qmc.begin(Wire, SENSOR_SDA, SENSOR_SCL)) {
71+
if (!qmc.begin(Wire, QMC6310U_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL)) {
7272
Serial.println("Failed to find QMC6310 - check your wiring!");
7373
while (1) {
7474
delay(1000);

examples/QMC6310_GetPolarExample/QMC6310_GetPolarExample.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void setup()
6868

6969
beginPower();
7070

71-
if (!qmc.begin(Wire, SENSOR_SDA, SENSOR_SCL)) {
71+
if (!qmc.begin(Wire, QMC6310U_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL)) {
7272
Serial.println("Failed to find QMC6310 - check your wiring!");
7373
while (1) {
7474
delay(1000);

src/REG/QMC6310Constants.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
class QMC6310Constants
3838
{
3939
protected:
40-
// Unique I2C device address
41-
static constexpr uint8_t QMC6310_SLAVE_ADDRESS = 0x1C;
40+
4241

4342
// Register addresses
4443
static constexpr uint8_t REG_CHIP_ID = 0x00;

src/SensorQMC6310.hpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#include "REG/QMC6310Constants.h"
3333
#include "SensorPlatform.hpp"
3434

35+
static constexpr uint8_t QMC6310U_SLAVE_ADDRESS = 0x1C;
36+
static constexpr uint8_t QMC6310N_SLAVE_ADDRESS = 0x3C;
37+
3538
class Polar
3639
{
3740
public:
@@ -98,27 +101,27 @@ class SensorQMC6310 : public QMC6310Constants
98101
}
99102

100103
#if defined(ARDUINO)
101-
bool begin(TwoWire &wire, int sda = -1, int scl = -1)
104+
bool begin(TwoWire &wire, uint8_t addr = QMC6310U_SLAVE_ADDRESS, int sda = -1, int scl = -1)
102105
{
103-
if (!beginCommon<SensorCommI2C, HalArduino>(comm, hal, wire, QMC6310_SLAVE_ADDRESS, sda, scl)) {
106+
if (!beginCommon<SensorCommI2C, HalArduino>(comm, hal, wire, addr, sda, scl)) {
104107
return false;
105108
}
106109
return initImpl();
107110
}
108111
#elif defined(ESP_PLATFORM)
109112

110113
#if defined(USEING_I2C_LEGACY)
111-
bool begin(i2c_port_t port_num, int sda = -1, int scl = -1)
114+
bool begin(i2c_port_t port_num, uint8_t addr = QMC6310U_SLAVE_ADDRESS, int sda = -1, int scl = -1)
112115
{
113-
if (!beginCommon<SensorCommI2C, HalEspIDF>(comm, hal, port_num, QMC6310_SLAVE_ADDRESS, sda, scl)) {
116+
if (!beginCommon<SensorCommI2C, HalEspIDF>(comm, hal, port_num, addr, sda, scl)) {
114117
return false;
115118
}
116119
return initImpl();
117120
}
118121
#else
119-
bool begin(i2c_master_bus_handle_t handle)
122+
bool begin(i2c_master_bus_handle_t handle, uint8_t addr = QMC6310U_SLAVE_ADDRESS)
120123
{
121-
if (!beginCommon<SensorCommI2C, HalEspIDF>(comm, hal, handle, QMC6310_SLAVE_ADDRESS, sda, scl)) {
124+
if (!beginCommon<SensorCommI2C, HalEspIDF>(comm, hal, handle, addr, sda, scl)) {
122125
return false;
123126
}
124127
return initImpl();
@@ -127,10 +130,11 @@ class SensorQMC6310 : public QMC6310Constants
127130
#endif
128131

129132
bool begin(SensorCommCustom::CustomCallback callback,
130-
SensorCommCustomHal::CustomHalCallback hal_callback)
133+
SensorCommCustomHal::CustomHalCallback hal_callback,
134+
uint8_t addr = QMC6310U_SLAVE_ADDRESS)
131135
{
132136
if (!beginCommCustomCallback<SensorCommCustom, SensorCommCustomHal>(COMM_CUSTOM,
133-
callback, hal_callback, QMC6310_SLAVE_ADDRESS, comm, hal)) {
137+
callback, hal_callback, addr, comm, hal)) {
134138
return false;
135139
}
136140
return initImpl();

0 commit comments

Comments
 (0)