Skip to content

Commit 5097fa1

Browse files
committed
taskI2C: use Fastwire library for I2C communication instead of Wire
In certain cases, Wire can get stuck in an infinite loop. Example of such a case: connect the SDA bus to ground (with the other MPUs connected as well). Wire.endTransmission() will enter an infinite loop with no way to stop it (except resetting the Arduino). Now, this is a very bad thing because taskI2C has the highest task priority -- if it enters an infinite loop, all other tasks cannot run and it will seem like the Arduino crashed. To fix this, use the Fastwire library, which does not seem to have this problem.
1 parent 7f67c49 commit 5097fa1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Diff for: arduino/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ BOARD_TAG = mega
22
BOARD_SUB = atmega2560
33
MONITOR_BAUDRATE=115200
44
ARDUINO_SKETCHBOOK = ../
5-
ARDUINO_LIBS = Arduino_FreeRTOS_Library ucomm Wire I2Cdev MPU6050 TimerOne
5+
ARDUINO_LIBS = Arduino_FreeRTOS_Library ucomm I2Cdev MPU6050 TimerOne
6+
CPPFLAGS=-DI2CDEV_IMPLEMENTATION=3
67
include ../.Arduino-Makefile/Arduino.mk

Diff for: arduino/taskI2C.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "taskI2C.h"
22
#include "taskComm.h"
3-
#include <Wire.h>
43
#include <I2Cdev.h>
54
#include <MPU6050.h>
65
#include <stdbool.h>
@@ -51,7 +50,7 @@ isMpu2Zeroes(const ucomm_Sample *sample)
5150
void
5251
taskI2C_setup()
5352
{
54-
Wire.begin();
53+
Fastwire::setup(100, true);
5554

5655
mpu1Active = setupMpu(&mpu1);
5756
mpu2Active = setupMpu(&mpu2);

0 commit comments

Comments
 (0)