Skip to content

Commit e27856c

Browse files
authored
Merge pull request #362 from adafruit/2nd-i2c
add second hardware i2c as Wire1 for cplayground bluefruit
2 parents d901f66 + e43abed commit e27856c

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

libraries/Wire/Wire.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,9 @@
3434
class TwoWire : public Stream
3535
{
3636
public:
37-
#if defined(NRF52) || defined(NRF52_SERIES)
3837
TwoWire(NRF_TWIM_Type * p_twim, NRF_TWIS_Type * p_twis, IRQn_Type IRQn, uint8_t pinSDA, uint8_t pinSCL);
39-
#else
40-
TwoWire(NRF_TWI_Type * p_twi, uint8_t pinSDA, uint8_t pinSCL);
41-
#endif
4238
void begin();
43-
#if defined(NRF52) || defined(NRF52_SERIES)
4439
void begin(uint8_t);
45-
#endif
4640
void end();
4741
void setClock(uint32_t);
4842

@@ -60,11 +54,10 @@ class TwoWire : public Stream
6054
virtual int read(void);
6155
virtual int peek(void);
6256
virtual void flush(void);
63-
#if defined(NRF52) || defined(NRF52_SERIES)
57+
6458
void onReceive(void(*)(int));
6559
void onRequest(void(*)(void));
6660
void onService(void);
67-
#endif
6861

6962
using Print::write;
7063

@@ -105,4 +98,8 @@ class TwoWire : public Stream
10598
extern TwoWire Wire;
10699
#endif
107100

101+
#if WIRE_INTERFACES_COUNT > 1
102+
extern TwoWire Wire1;
103+
#endif
104+
108105
#endif

libraries/Wire/Wire_nRF52.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ void TwoWire::onService(void)
392392
}
393393
}
394394

395+
#if WIRE_INTERFACES_COUNT > 0
395396
TwoWire Wire(NRF_TWIM0, NRF_TWIS0, SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn, PIN_WIRE_SDA, PIN_WIRE_SCL);
396397

397-
#if WIRE_INTERFACES_COUNT > 0
398398
extern "C"
399399
{
400400
void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void)
@@ -404,4 +404,16 @@ extern "C"
404404
}
405405
#endif
406406

407+
#if WIRE_INTERFACES_COUNT > 1
408+
TwoWire Wire1(NRF_TWIM1, NRF_TWIS1, SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn, PIN_WIRE1_SDA, PIN_WIRE1_SCL);
409+
410+
extern "C"
411+
{
412+
void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler(void)
413+
{
414+
Wire1.onService();
415+
}
416+
}
407417
#endif
418+
419+
#endif // NRF52_SERIES
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <Wire.h>
2+
3+
TwoWire *wi = &Wire;
4+
//TwoWire *wi = &Wire1;
5+
6+
void setup()
7+
{
8+
Serial.begin(115200); // start serial for output
9+
while ( !Serial ) delay(10); // for nrf52840 with native usb
10+
wi->begin(); // join i2c bus (address optional for master)
11+
}
12+
13+
void loop()
14+
{
15+
Serial.println("Scanning address from 0 to 127");
16+
for (int addr = 1; addr < 128; addr++)
17+
{
18+
wi->beginTransmission(addr);
19+
if ( 0 == wi->endTransmission() )
20+
{
21+
Serial.print("Found: 0x");
22+
Serial.print(addr, HEX);
23+
Serial.println();
24+
}
25+
}
26+
27+
delay(5000);
28+
}

variants/circuitplayground_nrf52840/variant.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ static const uint8_t SCK = PIN_SPI_SCK ;
112112
/*
113113
* Wire Interfaces
114114
*/
115-
#define WIRE_INTERFACES_COUNT 1
115+
#define WIRE_INTERFACES_COUNT 2
116116

117-
#define PIN_WIRE_SDA (28)
118-
#define PIN_WIRE_SCL (26)
117+
#define PIN_WIRE_SDA (2)
118+
#define PIN_WIRE_SCL (3)
119+
120+
#define PIN_WIRE1_SDA (28)
121+
#define PIN_WIRE1_SCL (26)
119122

120123
// QSPI Pins
121124
#define PIN_QSPI_SCK 29

0 commit comments

Comments
 (0)