Skip to content

Commit e28f479

Browse files
committed
FIX fix for I2C sensor - support for STM32 and Arduino
1 parent b0c5275 commit e28f479

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/MagneticSensorI2C.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,20 @@ MagneticSensorI2C::MagneticSensorI2C(MagneticSensorI2CConfig_s config){
4949

5050
void MagneticSensorI2C::init(){
5151

52+
#if defined(_STM32_DEF_) // if stm chips
53+
// I2C communication begin
54+
Wire.begin();
55+
Wire.setClock(clock_speed);
56+
Wire.setSCL(scl_pin);
57+
Wire.setSDA(sda_pin);
58+
#elif defined(ESP_H) // if esp32
5259
//I2C communication begin
5360
Wire.begin(sda_pin, scl_pin, clock_speed);
61+
#else
62+
// I2C communication begin
63+
Wire.begin();
64+
Wire.setClock(clock_speed);
65+
#endif
5466

5567
// velocity calculation init
5668
angle_prev = 0;

0 commit comments

Comments
 (0)