Merge pull request #362 from adafruit/2nd-i2c

add second hardware i2c as Wire1 for cplayground bluefruit
This commit is contained in:
hathach authored and GitHub committed 2019-10-21 11:48:23 +07:00
commit e27856c7ab
4 files changed
+52 -12

No files matched your search

+5 -8
View File
@@ -34,15 +34,9 @@
class TwoWire : public Stream
{
public:
#if defined(NRF52) || defined(NRF52_SERIES)
TwoWire(NRF_TWIM_Type * p_twim, NRF_TWIS_Type * p_twis, IRQn_Type IRQn, uint8_t pinSDA, uint8_t pinSCL);
#else
TwoWire(NRF_TWI_Type * p_twi, uint8_t pinSDA, uint8_t pinSCL);
#endif
void begin();
#if defined(NRF52) || defined(NRF52_SERIES)
void begin(uint8_t);
#endif
void end();
void setClock(uint32_t);
@@ -60,11 +54,10 @@ class TwoWire : public Stream
virtual int read(void);
virtual int peek(void);
virtual void flush(void);
#if defined(NRF52) || defined(NRF52_SERIES)
void onReceive(void(*)(int));
void onRequest(void(*)(void));
void onService(void);
#endif
using Print::write;
@@ -105,4 +98,8 @@ class TwoWire : public Stream
extern TwoWire Wire;
#endif
#if WIRE_INTERFACES_COUNT > 1
extern TwoWire Wire1;
#endif
#endif
+13 -1
View File
@@ -392,9 +392,9 @@ void TwoWire::onService(void)
}
}
#if WIRE_INTERFACES_COUNT > 0
TwoWire Wire(NRF_TWIM0, NRF_TWIS0, SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn, PIN_WIRE_SDA, PIN_WIRE_SCL);
#if WIRE_INTERFACES_COUNT > 0
extern "C"
{
void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void)
@@ -404,4 +404,16 @@ extern "C"
}
#endif
#if WIRE_INTERFACES_COUNT > 1
TwoWire Wire1(NRF_TWIM1, NRF_TWIS1, SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn, PIN_WIRE1_SDA, PIN_WIRE1_SCL);
extern "C"
{
void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler(void)
{
Wire1.onService();
}
}
#endif
#endif // NRF52_SERIES
@@ -0,0 +1,28 @@
#include <Wire.h>
TwoWire *wi = &Wire;
//TwoWire *wi = &Wire1;
void setup()
{
Serial.begin(115200); // start serial for output
while ( !Serial ) delay(10); // for nrf52840 with native usb
wi->begin(); // join i2c bus (address optional for master)
}
void loop()
{
Serial.println("Scanning address from 0 to 127");
for (int addr = 1; addr < 128; addr++)
{
wi->beginTransmission(addr);
if ( 0 == wi->endTransmission() )
{
Serial.print("Found: 0x");
Serial.print(addr, HEX);
Serial.println();
}
}
delay(5000);
}
@@ -112,10 +112,13 @@ static const uint8_t SCK = PIN_SPI_SCK ;
/*
* Wire Interfaces
*/
#define WIRE_INTERFACES_COUNT 1
#define WIRE_INTERFACES_COUNT 2
#define PIN_WIRE_SDA (28)
#define PIN_WIRE_SCL (26)
#define PIN_WIRE_SDA (2)
#define PIN_WIRE_SCL (3)
#define PIN_WIRE1_SDA (28)
#define PIN_WIRE1_SCL (26)
// QSPI Pins
#define PIN_QSPI_SCK 29