Skip to content

Commit 4f4d97c

Browse files
Laurence BankLaurence Bank
authored andcommitted
added support for custom HW I2C on Mbed targets
1 parent 4d53028 commit 4f4d97c

File tree

5 files changed

+231
-77
lines changed

5 files changed

+231
-77
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ Copyright (c) 2018 BitBank Software, Inc.
44
Written by Larry Bank ([email protected])
55
Project started 10/12/2018
66

7-
The purpose of this code is to provide a simple C library which can bit-bang
8-
the I2C protocol on any 2 GPIO pins on any system. The I2C protocol doesn't
7+
The purpose of this code is to provide a simple C library which can manage I2c
8+
in a consistent way across different platforms, in addition to providing
9+
software bit-bang of the protocol on any 2 GPIO pins. The I2C protocol doesn't
910
require any special functionality of the pins beyond standard GPIO features.
1011
The reason I wrote it was for getting easy access to I2C devices on
1112
various microcontrollers that don't necessarily have exposed I2C interfaces.

examples/I2C_Detector/I2C_Detector.ino

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838

3939
// Arbitrary pins I used for testing with an ATmega328p
4040
// Define as -1, -1 to use the Wire library over the default I2C interface
41-
//#define SDA_PIN -1
42-
//#define SCL_PIN -1
41+
#define SDA_PIN 13
42+
#define SCL_PIN 14
4343
// M5Stack Atom Grove connector pin assignments
4444
//#define SDA_PIN 32
4545
//#define SCL_PIN 26
4646
// M5Stack Atom internal I2C connected to the IMU
4747
//#define SDA_PIN 25
4848
//#define SCL_PIN 21
4949
// M5Stack Core2 internal I2C
50-
#define SDA_PIN 21
51-
#define SCL_PIN 22
50+
//#define SDA_PIN 21
51+
//#define SCL_PIN 22
5252
//
5353
// If you don't need the explicit device names displayed, disable this code by
5454
// commenting out the next line
@@ -66,8 +66,10 @@ BBI2C bbi2c;
6666

6767
void setup() {
6868
Serial.begin(115200);
69+
while (!Serial) {};
70+
Serial.println("I2C Scan Demo");
6971
memset(&bbi2c, 0, sizeof(bbi2c));
70-
bbi2c.bWire = 0; // use bit bang, not wire library
72+
bbi2c.bWire = 1; // use bit bang, not wire library
7173
bbi2c.iSDA = SDA_PIN;
7274
bbi2c.iSCL = SCL_PIN;
7375
I2CInit(&bbi2c, 100000L);

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=BitBang_I2C
2-
version=2.1.5
2+
version=2.2.0
33
author=Larry Bank <[email protected]>
44
maintainer=Larry Bank <[email protected]>
55
sentence=Bit-bang the I2C protocol on any 2 GPIO pins on any system.

0 commit comments

Comments
 (0)